'didRegisterUserNotificationSettings: is called, but didRegisterForRemoteNotificationsWithDeviceToken is not called in Xcode9
all.
I want to ask you about push notification settings.
Environments:
MacOS[High Sierra10.13.3]
Xcode9.2(9C40b)
Devices
- iPhone6S[iOS10.3.3]
- iPhoneX [iOS11.2.6]
Language:
Cocos2d-x (Objective-c)
This problem occurs suddenly, and above methods are called before,
so basic settings must have been correctly done such as "Capabilities", "Provisioning Profiles".
And of course, network is connected to wifi.
So now, here is my code snippet.
- (BOOL)application: (UIApplication*)application didFinishLaunchingWithOptions: (NSDictionary*)launchOptions {
[[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error) {
[[UIApplication sharedApplication] registerForRemoteNotifications];
}];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[application registerForRemoteNotifications];
}
Also, I try this one.
- (BOOL)application: (UIApplication*)application didFinishLaunchingWithOptions: (NSDictionary*)launchOptions {
UIUserNotificationSettings* setting = [UIUserNotificationSettings settingsForTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories: nil];
[[UIApplication sharedApplication] registerUserNotificationSettings: setting];
}
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[application registerForRemoteNotifications];
}
I can see push notification dialog when app is launched, push allow or deny button, requestAuthorizationWithOptions callback is invoked, but nothing happens.
I repeatedly uninstall and install app, but nothing changed.
Added(14/03/2018 18:53)
I create new test project and use the same bundle identifier and Provisioning Profiles.
Then, didRegisterForRemoteNotificationsWithDeviceToken is invoked correctly.
So, maybe configuration of Provisioning Profiles and AppID are ok, my project's setting is incorrect...
Solution 1:[1]
If the project is targeting iOS version 10.0+, Apple recommends utilizing the new method for asking for notification permissions:
requestAuthorizationWithOptions:completionHandler:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eli017 |
