所有。
我想问你推送通知设置。
环境:
MacOS [High Sierra10.13.3]
Xcode9.2(9C40b)
设备
- iPhone6S [iOS10.3.3]
- iPhoneX [iOS11.2.6]
语言
Cocos2d-x(Objective-c)
这个问题突然发生,上面的方法被调用,
因此必须正确完成基本设置,例如"功能","配置配置文件"。
当然,网络连接到wifi。
现在,这是我的代码段。
- (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];
}
另外,我试试这个。
- (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];
}
我可以在启动应用时看到推送通知对话框,按下允许或拒绝按钮,调用requestAuthorizationWithOptions
回调,但没有任何反应。
我反复卸载并安装应用程序,但没有任何改变。
已添加(14/03/2018 18:53)
我创建了新的测试项目并使用相同的包标识符和Provisioning Profiles。
然后,正确调用didRegisterForRemoteNotificationsWithDeviceToken
。
因此,配置配置文件和AppID的配置都可以,我的项目设置不正确......