ios9 接收重复推送通知

问题描述:

我在 iOS9 中两次收到相同的推送通知,尽管它在 iOS8 中运行良好.

I am receiving the same push notification twice in iOS9, although it is working fine in iOS8.

我使用以下代码注册推送通知:

I have used the following code to register with push notifications:

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
{
    // use registerUserNotificationSettings
    UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:( UIUserNotificationTypeSound | UIUserNotificationTypeAlert|UIUserNotificationTypeBadge) categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:setting];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
    // use registerForRemoteNotifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert |UIRemoteNotificationTypeBadge)];
}

#else

// use registerForRemoteNotifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

#endif

我在几个应用中都遇到过这个问题,如果你调用 registerUserNotificationSettings: 超过 1 次,看起来会出现重复.

I had this problem in several apps, and looks like duplicates appear if you call registerUserNotificationSettings: more than 1 time.

此答案中的更多详细信息:https://stackoverflow.com/a/35064911/4495995

More details in this answer: https://stackoverflow.com/a/35064911/4495995