18

I have an app with local notification at the App Store.

In the last 4 version updates to my app, there were customers who experienced something strange - the app lost control over previous notifications, they kept getting all notification scheduled before the update, even though they should've been canceled by [[UIApplication sharedApplication] cancelAllLocalNotifications]!

While communicating with these customers, I told them to turn off reminders, something that performs cancelAllLocalNotifications, but they claim to keep getting reminders.

Also, reinstalling the app doesn't get rid of the old notifications! It's as if iOS thinks this is a different app.

It doesn't happen to most of my customers, only to rare few - but still, it happens every update!

How can it be?

Update

3 years later and it's still happening.

Every update some customers keep receiving local notifications, but the app can't see those, nor can control them.

Can anyone solve this or prove it is a bug of iOS?

Kof
  • 23,893
  • 9
  • 56
  • 81
  • can they not just delete and re-install the app? something strange has obviously happended. so best start again. maybe it was part of the 4th July update bug that apple had? – Nik Burns Jul 08 '12 at 18:42
  • "reinstalling the app doesn't get rid of the old notifications", some of them tried. It's not related to 4-Jul because it happened on the previous 2 updates as well. – Kof Jul 09 '12 at 06:19
  • btw - I've opened a ticket to Apple, they weren't able to find the reason for this. – Kof Oct 18 '12 at 15:34
  • I am having the same issue. Same weekly scheduled notification getting fired multiple times now, which is very annoying. Is this a bug on iOS? Have you solved your issue? – Kiran Shakya May 27 '15 at 08:46
  • It happens much less (at least according to support emails), but I believe it's still out there. – Kof May 29 '15 at 16:57
  • 2
    "reinstalling the app doesn't get rid of the old notifications" For this to work you will need to uninstall the app and wait 24 hours to resintall it. Thats because Apple thinks the user may uninstall an app by accident and keeps the notifications cached to be able to deliver them in case the user resintall the app it in the next 24 hours. – Francisco Félix Oct 14 '15 at 20:09
  • Did this begin with update to iOS 8? And, are you also using remote notifications? – Sheamus Oct 15 '15 at 20:42
  • 1
    Could we see the code you use to generate the notifications and when it's called please? – James Webster Oct 16 '15 at 13:24
  • @desveladisimo that's very interesting, should try that as a workaround. – Kof Oct 16 '15 at 21:26
  • @Sheamus no, it's been happening for over 3 years, probably since iOS 6. – Kof Oct 16 '15 at 21:27
  • @James Webster I've actually opened a tech support ticket to Apple, sent them the code and they couldn't find a reason for this to happen (code wise), it happens only to a few percentage of users, it's usually quite rare and only after app update. – Kof Oct 16 '15 at 21:30
  • So I have no reason to believe it has anything to do with the code. It may however be related to the fact the app schedules ~40 local notifications, most apps doesn't do that, this may explain why it wasn't happening to others and why it slipped off Apple's QA. – Kof Oct 16 '15 at 21:33

4 Answers4

2

Did you check How does UIApplication cancelAllLocalNotifications work between app updates? It doesn't have definitive answers, but maybe it would be useful.

Try to find out what's so special about the customer that experience this:

  • Is it always the same customers who experience this behavior?
  • Which iOS version they use?
  • How are they using you app differently? Have a lot of notification scheduled?
  • How are they making the update? (over-the-air, sync, etc.)
Community
  • 1
  • 1
Yasei No Umi
  • 1,574
  • 9
  • 23
  • 1. Not the same customers, different ones every time. 2. I'll check with them. 3. All customers have the same number of notifications scheduled. 4. I'll check. – Kof Jul 13 '12 at 05:22
  • Not the answer and didn't fix my problem, but I had to give the bounty reward to someone. – Kof Oct 19 '15 at 09:47
1

I had similar issues with notifications. My solution to actually delete was to set a specific date and only notify once. The line applicationIconBadgeNumber = 0 removes the notification from notifications list. The badge number is only set when the user entered the app. For the case when the user didn't see the message yet you can just add a check in applicationWillEnterForeground and display a proper UIAlertView with the same message as the notification, and you can get the last notification in a similar way by using notificationArray. When you need to set a new notification "isNotified" needs setValue:@"0" and be synchronized. When I use multiple notifications I save states like this:

[userDefaults setValue:@"1" forKey:[NSString stringWithFormat:@"notification-%@", @"12"]];
NSInteger number = [[userDefaults objectForKey:[NSString stringWithFormat:@"notification-%@", @"12"]] integerValue];

In MainViewController.m

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSInteger alreadyNotified = [[userDefaults objectForKey:@"isNotified"] integerValue];

if (alreadyNotified == 0) {

    NSInteger seconds = 60;
    NSString *message = @"Just testing!";

    UILocalNotification *notification = [[UILocalNotification alloc] init];

    UIUserNotificationSettings *currentSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];
    BOOL allowNotif = (currentSettings.types != UIUserNotificationTypeNone);
    BOOL allowsSound = (currentSettings.types & UIUserNotificationTypeSound) != 0;
    BOOL allowsBadge = (currentSettings.types & UIUserNotificationTypeBadge) != 0;
    BOOL allowsAlert = (currentSettings.types & UIUserNotificationTypeAlert) != 0;

    if (notification)
    {
        if (allowNotif)
        {
            NSDate *now = [NSDate date];
            if (seconds > 0) {
                now = [now dateByAddingTimeInterval:seconds];
            }
            notification.fireDate = now;
            notification.timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
            notification.repeatInterval = 0;
            NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"1", @"id", message, @"message", nil];
            notification.userInfo = userInfo;
        }
        if (allowsAlert)
        {
            notification.alertBody = message;
        }
        if (allowsBadge)
        {
            notification.applicationIconBadgeNumber = 1;
        }
        if (allowsSound)
        {
            notification.soundName = UILocalNotificationDefaultSoundName;
        }

        [[UIApplication sharedApplication] scheduleLocalNotification:notification];

        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        [userDefaults setValue:@"1" forKey:@"isNotified"];
        [userDefaults synchronize];
    }

} else {

    UIApplication *app = [UIApplication sharedApplication];
    NSArray *notificationArray = [app scheduledLocalNotifications];
    for (int i=0; i<[notificationArray count]; i++)
    {
        UILocalNotification *notification = [notificationArray objectAtIndex:i];
        [app cancelLocalNotification:notification];
    }
}

In AppDelegate.m

- (void)applicationWillEnterForeground:(UIApplication *)application {
   application.applicationIconBadgeNumber = 0;
}
Gillsoft AB
  • 4,185
  • 2
  • 19
  • 35
  • This approach deletes all notifications directly after reading them, so after an app update it should not trigger old notifications. At least it doesn't do that in my app. I tried just now to reinstall, and only new (not previously shown) scheduled notifications were shown. – Gillsoft AB Oct 18 '15 at 11:18
0

Add the following code to your application:didFinishLaunchingWithOptions: method to clear all the notification.

 [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1];
 [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
 [[UIApplication sharedApplication] cancelAllLocalNotifications];

Once done you can add the new notifications.

IamAnil
  • 496
  • 5
  • 19
-1

Hey that is what is also happening with my app as well. My local notifications are getting fired in below scenerios :
1. user has deleted the app

  1. Using same app on same device but with different user name, they getting alerts for last logged in user.

-Actually its UILocalNotification behave, we have to cancel them else IOS retain them for at least some time(not sure how long) when app is deleted and they were scheduled by the app at deletion time and were not canceled.

So always make sure when ever your app install happens,keep a check & cancel all scheduled notifications.

like

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    if(//its a fresh install){

     [[UIApplication sharedApplication] cancelAllLocalNotifications];

    }


    }

cancelAllLocalNotifications will cancel all existing notifications.

Hope it will help.

Ash
  • 5,525
  • 1
  • 40
  • 34
  • Nope, as indicated previously, `cancelAllLocalNotifications` has been called several times and it didn't stop the old notifications. – Kof Oct 16 '16 at 13:39