2

Does anyone know how the cancelAllLocalNotifications method works on UIApplication? I'm wondering specifically how iOS knows what to cancel. Does it know by App ID? Or does it use the version number of the app somehow?

What I'm experiencing right now is more notifications than I expect. This is the workflow:

  1. Cancel all notifications on app start
  2. Schedule notifications on app exit
  3. *When scheduling, add the notification info to a "Recents" list
  4. *When scheduling, schedule only 1 notification per day (verified in logging statements in XCode before I disconnect my phone).

Now, this is what I'm experiencing:

  1. Receive 4 notifications per day
  2. Only 1 of the notifications shows up in my "Recents" list (which makes sense, because that's all I'm scheduling)

Previously, I my # of notifications per day set to 3. Then I updated the version number (say, from 1.1.0 to 1.1.1) for the "cancelAllLocalNotifications" method was called.

So, if the canceling of notifications is based upon the app's version/bundle ID in any way, I'm getting old notifications along with the new ones.

However, if it is not, and iOS knows to cancel notifications scheduled from the previous version 1.1.0, then I have no idea where these additional notifications are coming from.

thephatp
  • 1,479
  • 1
  • 20
  • 37
  • At app startup, where are you calling the cancelAllLocalNofications? – greenhorn Mar 02 '12 at 22:53
  • @vipinagg, good point. I'm calling it in two places: (1) in the app delegate when a notification is received (that's wrong right off the bat, but it turns out it doesn't matter b/c of where the second occurrence is), and (2) in the "applicationDidEnterBackground" method, I call a function that schedules all of the notifications, and the first thing that function does is cancel all notifications before scheduling any new ones. But good point--guessing you questioned if it was only called in application:didFinishLaunchingWithOptions: but not in "applicationWillEnterForeground:". – thephatp Mar 03 '12 at 02:09
  • Follow my answer on this topic. [http://stackoverflow.com/a/42724415/1720559](http://stackoverflow.com/a/42724415/1720559) – Linh Nguyen Mar 10 '17 at 17:34

1 Answers1

1

I believe that Local and Remote notifications are based upon the App ID (AppleID + BundleID). Therefore, regardless of version, you are going to get notifications. I can see the argument both for and against this implementation.

Did you need some strategies for dealing with this... functionality?

teamaxe
  • 316
  • 1
  • 7
  • Yes, definitely need some strategies for dealing with it. Essentially, I'd need to somehow cancel all scheduled notifications prior to the user updating the app (b/c of having a new App ID). Alternatively, though I highly doubt this is possible, if I could force cancellation after the app is updated, that would suffice (doubt Apple gives this level of control). – thephatp Mar 02 '12 at 21:46