处理本地和远程通知
用法示例:
/* Instance of your custom APNs/local notification manager */
private var pushManager: AppleNotificationManager!
注册:
func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
// Called to tell the delegate the types of notifications that can be used to get the user’s attention
pushManager.didRegisterSettings(notificationSettings)
}
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
// Tells the delegate that the app successfully registered with Apple Push Notification service (APNs)
pushManager.didRegisterDeviceToken(deviceToken)
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
// Sent to the delegate when Apple Push Notification service cannot successfully complete the registration process.
pushManager.didFailToRegisterDeviceToken(error)
}
远程通知处理:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
// Remote notification arrived, there is data to be fetched
// Handling it
pushManager.handleNotification(userInfo,
background: application.applicationState == .Background
)
}
本地通知处理:
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
pushManager.handleLocalNotification(notification, background: false)
}
处理行动(不建议使用):
func application(application: UIApplication, handleActionWithIdentifier identifier: String?, forRemoteNotification userInfo: [NSObject : AnyObject],
completionHandler: () -> Void) {
pushManager.handleInteractiveRemoteNotification(userInfo, actionIdentifier: identifier, completion: completionHandler)
}