ios - registerUserNotificationSettings 不显示提示 iOS 8

标签 ios objective-c uilocalnotification

我似乎无法在 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 中的预期行为。 至少在照片库、麦克风访问等方面是一样的:

权限提示行为

  1. 首次使用时弹出(或至少是使用它的请求)
  2. Apple 在设置中添加了一个条目(例如隐私,或就在通知设置下)

第一次使用

Permissions promt

设置应用中,您可以为每个应用配置通知

  1. 向下滚动,选择您的应用
  2. 选择通知
  3. 启用/禁用它们,或调整它们的行为

在 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:

  1. Delete your app from the device.
  2. Turn the device off completely and turn it back on.
  3. Go to Settings > General > Date & Time and set the date ahead a day or more.
  4. 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/

相关文章:

iphone - 在本地通知中设置 repeatInterval

cocoa-touch - UIView 动画取消任何触摸输入?

iphone - 如果点击 ScrollView,则隐藏/显示按钮和 UIImageVIew

ios - 在 iOS 中绘制沿路径均匀分布的图像

objective-c - 检测卷何时安装在 OS X 上

ios - 在 block 内设置属性是否安全

iphone - 当应用程序处于后台或事件状态时的 UILocalNotification

ios - 如何在不检查应用程序状态的情况下确定是否点击了 UILocalNotification?

ios - 使用 widthSegmentCount 属性修复外观清晰的几何对象

iphone - Objective-C 中类的内存大小