Receiving duplicate push notification ios9

僤鯓⒐⒋嵵緔 提交于 2019-11-30 04:40:29
Vladimir K

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

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

It is apparently an Apple issue. I've faced the same issue many times across apps. https://forums.developer.apple.com/thread/13414

Muhammad Ishaq

From iOS 9 every time when you uninstall and than re-install the app again a new device token has assigned this might be the reason that you receives the multiple push notifications.

Actually I read out from one forum, they provide the solution that when you generating a payload that add one extra custom any random value so that each payload has some unique value. in my case in vb.net I am using DateTime.Now.ToString("MMddyyyyHHmmssfff") to add a unique time stamp with milliseconds. I hope its work I implemented this but not tested so far.

hardik vyas

I am using this and this is working fine in Ios9 also, please try it. Add this in your 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)];
}

Method for call is

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

First check your database and make sure you didn't get the device token twice, quite possible that you have duplicate entries of the same token.

Secondly, If you install/uninstall the app within 3 to 4 days its possible that you get the notification twice or even thrice.

Solution: Please uninstall the app for a week if possible than install the app again.

Thank You.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!