Is there a callback to the app delegate when a remote notification is received?
After receiving the remote notification and the user takes action (other than close/dismiss), the app delegate gets callbacks:
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
or if the app is registered for notification actions:
-(void) application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
My question is does the app get a callback when the remote notification is received? That is before the user takes any action. Thanks for your input.
No, the app doesn't get any indication that the notification has reached the device. It only gets a delegate call when the notification actually gets sent to the app as you describe in the two cases in your question.
是的,当收到远程通知时,app当然会获得这些代理方法的回调。
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
print("DEVICE TOKEN = (deviceToken)")
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
print(error)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print(userInfo)
}
链接地址: http://www.djcxy.com/p/67262.html
上一篇: 使用GCM的Swift远程推送通知