registerUserNotificationSettings 未显示提示 iOS 8

registerUserNotificationSettings not showing prompt iOS 8

我似乎无法在 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);
}

但是一直没有提示。更烦人的是,设备锁定时会显示警报,但不会发出通知警报声。关于变通的任何想法?

iOS11+ 更新:

因为 iOS 11 Resetting the Push Notifications Permissions Alert on iOS 程序似乎不再需要了。只是 un-/reinstall 应用程序。


使用您的代码,我在第一次启动应用程序时收到提示,并且仅在第一次启动时收到提示。但是 afaik,这是 iOS 中的预期行为。 至少照片库、麦克风访问等是一样的:

权限提示行为

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

首次使用

Settings 应用程序中,您可以为每个应用程序配置 Notifications

  1. 向下滚动,select 您的应用
  2. Select Notifications
  3. Enable/Disable他们,或者调整他们的行为

重置 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 8 中没有显示相同的问题,但在 iOS 10 中显示了警报弹出消息,此警报消息将在应用程序周期中仅显示一次。除非你删除并重新安装新的。

- (void)registerLocalNotification{

    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}

如果有人仍然卡住,切换选项对我有用。就是这个

UNAuthorizationOptions options = UNAuthorizationOptionAlert & UNAuthorizationOptionSound;

我把它改成了这个

UNAuthorizationOptions options = UNAuthorizationOptionAlert;

然后回到

UNAuthorizationOptions options = UNAuthorizationOptionAlert & UNAuthorizationOptionSound;