Search code examples
iosobjective-cnotificationsuilocalnotificationuiswitch

multiple uiswitch with local notification repeatinterval, don't relly like each others in my app


So, here is my life story that I can't seem to figure out what's wrong!!!

I have an app that's already in the store and it has a weird issue which it gives out mixed results.

I have two switches in my main view both controls local notification with repeat intervals.

now I've set up the switches right and ready to go. (I guess). However, when repeat intervals are scheduled they have to be cancelled again when the user decided not to receive notifications. So, I had my switches coded like that:

- (void)applicationDidEnterBackground:(UIApplication *)application
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
BOOL switchOn = [userDefaults boolForKey:@"switchO"];

if (switchOn) {

    [self Firstnotif];
    [self Secondnotif];
    [self Thirdnotif];
    [self Lastnotif];

}

else {   [[UIApplication sharedApplication] cancelAllLocalNotifications];    }


 BOOL switchOn2 = [userDefaults boolForKey:@"switchO2"];

if (switchOn2) {


[self Firstnotif];


}

else {   [[UIApplication sharedApplication] cancelAllLocalNotifications];    }


}

notice I have used the method Firstnotif twice in both switches.

My issues are:

  • I used to have only one switch and when they turn the first switch on to receive these four notification, doesn't work with all of the users. so I tell them to switch it off, press home button, open app again switch it on and home button again. It works!!!! why?

  • Now, since I've added another switch new mixed results are appearing. the second switch is to only fire first notification with it's repeat interval. Some say it works, some say not. others say when I turn the other one it does and does not. What are they facing here??

My questions,

Am I canceling the repeat intervals in the right way?

What could be wrong with my app? and I'll provide you with more codes if needed.

I appreciate your inputs as I've spent weeks on these issues with no luck.


Solution

  • I solved it!

    I replaced the cancellation request under applicationDidBecomeActive method and removed my else

    guess what? It worked!!! :)