我似乎无法在 iOS 8.1 或 8.2 中收到显示 registerUserNotificationSettings
的提示。
这是我在 didFinishLaunchingWithOptions
中所做的:
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
#ifdef __IPHONE_8_0
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert
|UIUserNotificationTypeSound | UIUserNotificationTypeBadge) categories:nil];
NSLog(@"Reg settings %@", settings);
[application registerUserNotificationSettings:settings];
#endif
}
这里也得到了正确的回电:
- (void)application:(UIApplication *)application
didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{
NSLog(@"Did register - %@", notificationSettings);
}
但没有显示任何提示。更烦人的是,设备锁定时会显示警报,但不会发出通知警报声。关于变通的任何想法?
最佳答案
iOS 11+ 更新:
自 iOS 11 以来,在 iOS 上重置推送通知权限警报
程序似乎不再是必需的。只需卸载/重新安装该应用程序即可。
使用您的代码,我在第一次启动应用程序时收到提示,并且仅在第一次启动时收到提示。但是 afaik,这是 iOS 中的预期行为。 至少在照片库、麦克风访问等方面是一样的:
权限提示行为
- 首次使用时弹出(或至少是使用它的请求)
- Apple 在设置中添加了一个条目(例如隐私,或就在通知设置下)
第一次使用
在设置
应用中,您可以为每个应用配置通知
- 向下滚动,选择您的应用
- 选择
通知
- 启用/禁用它们,或调整它们的行为
在 iOS 上重置推送通知权限警报
The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.
If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by following these steps:
- Delete your app from the device.
- Turn the device off completely and turn it back on.
- Go to Settings > General > Date & Time and set the date ahead a day or more.
- Turn the device off completely again and turn it back on.
来源:https://developer.apple.com/library/ios/technotes/tn2265/_index.html
关于ios - registerUserNotificationSettings 不显示提示 iOS 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29265433/