Somewhat similar to When is didRegisterForRemoteNotificationsWithDeviceToken called?.
When the user first installed the app and it prompts whether t
Check the Application State inside the function didReceiveRegistrationToken
let state = UIApplication.shared.applicationState
if state == .background || state == .inactive {
print("Background")
} else if state == .active {
print("foreground")
}
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 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.