Somewhat similar to When is didRegisterForRemoteNotificationsWithDeviceToken called?.
When the user first installed the app and it prompts whether to accept notification, will didRegisterForRemoteNotificationsWithDeviceToken
be called if the user accepts it?
I'm currently calling registerForRemoteNotificationTypes
after the user successfully signs in or creates an account.
In subsequently launches, the didRegisterForRemoteNotificationsWithDeviceToken
delegate is called even without calling registerForRemoteNotificationTypes
in AppDelegate.
If I follow the docs and example code:
By requesting the device token and passing it to the provider every time your application launches, you help to ensure that the provider has the current token for the device.
- (void)applicationDidFinishLaunching:(UIApplication *)app {
// other setup tasks here....
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:...
}
But by requesting the token when the app launches, the delegate will be called twice.
A couple of questions and clarity needed:
For the initial prompt to happen, a call for registerForRemoteNotificationTypes
must be made for the prompt to appear? But, the delegate will be called twice if I call this manually in AppDelegate. Is it suppose be that way?
If the user accepts the initial prompt, will didRegisterForRemoteNotificationsWithDeviceToken
be called automatically? Or must we invoke
registerForRemoteNotificationTypes
in AppDelegate? But then the delegate will be called twice for future launches?
If the user denies and later accept it via Setting, what happens?
UPDATE
0. For the initial prompt to happen, a call for registerForRemoteNotificationTypes
must be made for the prompt to appear? But, the delegate will be called twice if I call this manually in AppDelegate. Is it suppose be that way? This isn't true. Found out that there were actually 2 registerForRemoteNotiicationTypes
being made in AppDelegate.
If the user accepts the initial prompt, will didRegisterForRemoteNotificationsWithDeviceToken be called automatically? No, Your remote notification registration process starts when 'allow access' is clicked, but didRegisterForRemoteNotificationsWithDeviceToken method is called only on successful APNS registration.
If your application has previously registered, calling registerForRemoteNotificationTypes: results in the operating system passing the device token to the delegate immediately without incurring additional overhead
You can determine whether an application is launched as a result of the user tapping the action button or whether the notification was delivered to the already-running application by examining the application state. In the delegate’s implementation of the application:didReceiveRemoteNotification: or application:didReceiveLocalNotification: method, get the value of the applicationState property and evaluate it. If the value is UIApplicationStateInactive, the user tapped the action button; if the value is UIApplicationStateActive, the application was frontmost when it received the notification.
Nope. this method only called once when app launch . if it is called twice then it will be called from your code. Try to see that if you are putting code like
[application registerUserNotificationSettings:mySettings];
[application registerForRemoteNotifications];
in didFinishLaunchingWithOptions
then in go to
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
is that you might be calling [application registerForRemoteNotifications];
so remove this code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With