When is didRegisterForRemoteNotificationsWithDeviceToken called?

前端 未结 3 2107
日久生厌
日久生厌 2021-01-03 18:30

There are a lot of questions about didRegisterForRemoteNotificationsWithDeviceToken but they all sidestep a very direct question which I cannot seem to find an exact answer

相关标签:
3条回答
  • 2021-01-03 18:42

    The application delegate will call the method upon successful registration of remote notification after you call this method in your UIApplication:

    (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types

    According to: http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html

    When you send this message, the device initiates the registration process with Apple Push Service. If it succeeds, the application delegate receives a device token in the application:didRegisterForRemoteNotificationsWithDeviceToken: method; if registration doesn’t succeed, the delegate is informed via the application:didFailToRegisterForRemoteNotificationsWithError: method. If the application delegate receives a device token, it should connect with its provider and pass it the token.

    Now, to elaborate further, normally an app will call the registerForRemoteNotificationTypes in your didFinishLaunchingWithOptions:(NSDictionary *)launchOptions in your application delegate. And therefore, the application:didRegisterForRemoteNotificationsWithDeviceToken is then usually called moments after the launch of the application.

    Edit: The application:didRegisterForRemoteNotificationsWithDeviceToken still gets called for subsequents registration after the first.

    0 讨论(0)
  • 2021-01-03 18:51

    There can be many reasons, check some reasons

    • If you run the app in the simulator, the application:didFailToRegisterForRemoteNotificationsWithError: method will be called as push notifications are not supported in the simulator.

    • Check your deice internet connection if not connect it.

    For more info check Link

    0 讨论(0)
  • 2021-01-03 18:53

    When the app is first run it will ask the user whether they will allow remote notifications. If they say yes then it will fire didRegisterForRemoteNotificationsWithDeviceToken at that time and every time after it will fire this function when the app is first opened. If they say no then it will not be fired unless they went into settings and allowed notifications on the app.

    0 讨论(0)
提交回复
热议问题