【问题标题】:Receiving duplicate push notification ios9接收重复的推送通知ios9
【发布时间】:2015-09-29 09:51:19
【问题描述】:

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

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

#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

【问题讨论】:

  • 您运行的是 iOS 9 测试版吗?这是那里的一个已知错误。这是一个 Apple 论坛讨论帖 -> forums.developer.apple.com/thread/13414
  • @Abhinav 我在 iOS 9.0 和 IOS 9.0.1 上运行。
  • 你解决过这个问题吗?我也有这个问题
  • 同样的问题!有什么解决办法吗?!
  • 这是 iOS9 上的一个 bug,Apple 尚未解决(9.0.2)。

标签: ios objective-c iphone apple-push-notifications


【解决方案1】:

我在几个应用程序中都遇到了这个问题,如果您拨打registerUserNotificationSettings: 超过 1 次,似乎会出现重复。

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

【讨论】:

    【解决方案2】:

    这显然是苹果的问题。我在应用程序中多次遇到同样的问题。 https://forums.developer.apple.com/thread/13414

    【讨论】:

      【解决方案3】:

      从 iOS 9 开始,每次您卸载并重新安装应用程序时,都会分配一个新的设备令牌,这可能是您收到多个推送通知的原因。

      实际上,我从一个论坛中读到,他们提供了一种解决方案,即当您生成一个有效负载时,该解决方案会添加一个额外的自定义任意随机值,以便每个有效负载都有一些唯一的值。在 vb.net 中,我使用 DateTime.Now.ToString("MMddyyyyHHmmssfff") 添加一个以毫秒为单位的唯一时间戳。我希望它的工作是我实现的,但到目前为止还没有经过测试。

      【讨论】:

        【解决方案4】:

        我正在使用它,这在 iOS9 中也可以正常工作,请尝试一下。将此添加到您的didFinishLaunchingWithOptions

        if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
        {
            [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
        else
        {
            [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
             (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
        }
        

        调用方法是

        - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{
            NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
            self.AppDeviceToken=[token stringByReplacingOccurrencesOfString:@" " withString:@""];
        }
        

        【讨论】:

          【解决方案5】:

          首先检查您的数据库并确保您没有两次获得设备令牌,很可能您有相同令牌的重复条目。

          其次,如果您在 3 到 4 天内安装/卸载应用程序,您可能会收到两次甚至三次通知。

          解决方案:如果可能,请卸载应用一周后再重新安装应用。

          谢谢。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2019-04-23
            • 2018-01-19
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-05-13
            • 2012-12-24
            相关资源
            最近更新 更多