Receiving duplicate push notification ios9
Asked Answered
D

5

23

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
Deaton answered 29/9, 2015 at 9:51 Comment(12)
Are you running on beta version of iOS 9? This was a known bug in there. Here is a Apple forum discussion thread -> forums.developer.apple.com/thread/13414Compose
@Compose I am running on iOS 9.0 and IOS 9.0.1.Deaton
Did you ever solve this issue? I too have this problemMaxie
Same problem here! Any solution?!Yacano
This is a bug on iOS9 and Apple has not solved it yet ( 9.0.2 ).Retarded
@Retarded Do you have a link to a support thread?Intellectualize
Still an issue as of iOS 9.1Interlinear
did you find a fix? Our app is now getting 10-20 notification receipts on device when only one APNS call was made.Axiology
@Deaton #33890378Agricola
Still not found any solution.Deaton
still an issue in ios 9.3.4..has anyone found the solution?Elzaelzevir
Apparently still happens in iOS12Bonnice
J
4

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://mcmap.net/q/586646/-does-my-app-display-second-time-notification-ios-9

Jehial answered 28/1, 2016 at 15:10 Comment(0)
S
2

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

Swung answered 10/11, 2015 at 6:54 Comment(0)
T
2

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.

Tutto answered 26/11, 2015 at 9:44 Comment(0)
C
0

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:@""];
}
Citystate answered 3/11, 2015 at 9:43 Comment(0)
T
-1

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.

Tutto answered 6/11, 2017 at 15:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.