Latest 1.1.4
License MIT
Platforms ios 9.0
Dependencies ObjectMapper


CI Status
Carthage Compatible

  • APNSUtil makes code simple settings and landing for apple push notification service.


  • Using apple push notification service simply
  • No need write codes for any iOS versions
  • Support chained functional programing


import APNSUtil


Implementation for main view controller

import UIKit
import APNSUtil

class ViewController: UIViewController {
    override func viewDidLoad() {

            .setTypes([.sound, .alert, .badge])             // setting user notification types
            .register()                                     // registering to use apns
            .processing(self) {                             // processing received apns payload
                let payload: APNSPayload = $0.payload()     // your custom payload with generic

                if $0.isInactive {
                    // TODO: write code to present viewController on inactive
                } else {
                    // TODO: write code to show toast message on active
            }.begin()   // begin receiving apns payload

Implementation for app delegate

import UIKit
import UserNotifications
import APNSUtil

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Logic for handling push notifications at initial startup
        APNSManager.shared.didFinishLaunching(withOptions: launchOptions, as: APNSPayload.self)
        return true

    // MARK: - Push Notification

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        // TODO: write code to update device token with your api server
    func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        // TODO: write code to update device token with your api server

    // MARK: - Push Notification for iOS 9

    func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        APNSManager.shared.didReceive(userInfo: userInfo, as: APNSPayload.self, isInactive: application.applicationState == .inactive)

    // MARK: - Push Notification for iOS 10 or higher

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        APNSManager.shared.didReceive(userInfo: notification.request.content.userInfo, as: APNSPayload.self, isInactive: false)
    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
        APNSManager.shared.didReceive(userInfo: response.notification.request.content.userInfo, as: APNSPayload.self, isInactive: true)

Implement your payload model

import APNSUtil
import ObjectMapper

extension RemoteNotificationElement {
    typealias T = APNSPayload

struct APNSPayload: Mappable {
    var msg: String?
    var id: String?

    init?(map: Map) {
        mapping(map: map)

    mutating func mapping(map: Map) {
        msg <- map["msg"]
        id <- map["id"]



CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.2+ is required to build APNSUtil 1.0.0+.

To integrate APNSUtil into your Xcode project using CocoaPods, specify it in your Podfile:

source ''
platform :ios, '9.0'

# Default
target '<Your Target Name>' do
    pod 'APNSUtil', '~> 1.1.4'

# for AppExtension
target '<Your Target Name>' do
    pod 'APNSUtil/AppExtension', '~> 1.1.4'

Then, run the following command:

$ pod install


Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Alamofire into your Xcode project using Carthage, specify it in your Cartfile:

github "pisces/APNSUtil" ~> 1.1.4

Run carthage update to build the framework and drag the built APNSUtil.framework into your Xcode project.


iOS Deployment Target 9.0 higher


Steve Kim, [email protected]


APNSUtil is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "APNSUtilAppExtension",
    "version": "1.1.4",
    "summary": "APNSUtil is makes code simple using apple push notification service.",
    "description": "APNSUtil is makes code simple using apple push notification service.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "pisces": "[email protected]"
    "source": {
        "git": "",
        "tag": "1.1.4"
    "platforms": {
        "ios": "9.0"
    "source_files": "APNSUtil/Classes/**/*",
    "dependencies": {
        "ObjectMapper": [
            "~> 3.1"
    "pod_target_xcconfig": {

Pin It on Pinterest

Share This