Skip to content

Wrap the Apple Push Notification Service (Remote Notification) written in Swift.

License

Notifications You must be signed in to change notification settings

xxxAIRINxxx/SwAPNs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwAPNs

Swift 2.1+ Platforms iOS Xcode 7.1+

Wrap the Apple Push Notification Service (Remote Notification) written in Swift.

Usage

SwAPNs.setup()

SwAPNs.registerType((UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert), categories: nil)

SwAPNs.failToRegisterPushHandler = { (error: NSError) in
    // didFailToRegisterForRemoteNotificationsWithError
    println(error)
}

SwAPNs.registerDeviceTokenHandler = { (deviceToken: NSData) in
    // didRegisterForRemoteNotificationsWithDeviceToken
    println(deviceToken)
}

SwAPNs.badgePushHandler = { (userInfo: [NSObject : AnyObject]) in
    // didReceiveRemoteNotification
    println(userInfo)
}

SwAPNs.soundPushHandler = { (userInfo: [NSObject : AnyObject]) in
    // didReceiveRemoteNotification
    println(userInfo)
}

SwAPNs.alertPushHandler = { (userInfo: [NSObject : AnyObject]) in
    // didReceiveRemoteNotification
    println(userInfo)
}

SwAPNs.backgroundFetchHandler = { (userInfo: [NSObject : AnyObject], completion: (UIBackgroundFetchResult) -> Void) in
    // didReceiveRemoteNotification fetchCompletionHandler
    println(userInfo)
    println(completion)
}

SwAPNs.handleActionHandler = { (identifier: String?, userInfo: [NSObject : AnyObject], completion: () -> Void) in
    // handleActionWithIdentifier forRemoteNotification
    println(identifier)
    println(userInfo)
    println(completion)
}

Method Swizzling (objc runtime)

replaced the following methods.

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler;

// iOS 8.0+ Only
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler;

Objc Version

ARNPush

Requirements

  • iOS 8.0+
  • Swift 2.2
  • Xcode 7.3+

Installation

SwAPNs.swift source file directly in your project.

License

MIT license. See the LICENSE file for more info.

About

Wrap the Apple Push Notification Service (Remote Notification) written in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published