为什么应用程序没有在 iOS 8 中注册推送通知?

问题描述:

我将我的 Xcode 升级到 Xcode 6.0.1,现在 iOS 8 设备不会进行远程通知注册.它适用于 iOS 7 设备.

I upgarded my Xcode to Xcode 6.0.1, now remote notification registration is not happening for iOS 8 device. It is working fine for iOS 7 device.

我在应用委托中添加了如下代码:

I have added the code in app delegate as mentioned below:

    //-- Set Notification
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge
     |UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

    NSLog(@"current notifications : %@", [[UIApplication sharedApplication] currentUserNotificationSettings]);
}
else
{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

即使当前的通知存在,也不是零.

Even the current notification is present, and it is not nil.

然而下面的方法没有被调用:

And yet the below method is not called :

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken

下面的截图说明我在后台模式下启用了某些选项:

Screenshot below explains that I have enabled certain options in background mode:

通知是在我的应用的设备设置中设置的.

And the notification is set in the device settings for my app.

需要拨打

[[UIApplication sharedApplication] registerForRemoteNotifications];

在您的 iOS8 代码路径中,注册用户通知设置后.

in your iOS8 code path, after registering the user notification settings.