Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receive local notifications after deleting and reinstalling an iphone app

I am using UILocalNotification in my project. I am stuck with an issue using the UILocalNotifications. If I schedule notifications for a week, delete the app and re install with no notification scheduled from the re-installed app, I receive the notifications for the times that were scheduled previously.

Even if there are no notifications scheduled from the present install, I receive the notifications. Is there a way to unschedule/remove these notifications?

like image 498
Nassif Avatar asked Jan 10 '13 12:01

Nassif


People also ask

Do push notifications work when app is closed iOS?

Apple does not offer a way to handle a notification that arrives when your app is closed (i.e. when the user has fully quit the application or the OS had decided to kill it while it is in the background). If this happens, the only way to handle the notification is to wait until it is opened by the user.

Why is an app not showing up in notifications iPhone?

Launch the Settings app and select Notifications. Next, choose the affected app and make sure Allow Notifications is toggled on. In addition, make sure Lock Screen, Notification Center, and Banners are enabled per your preferences.


1 Answers

Actually, when you schedule future notification, then delete app and then again re-install it, in this case you will receive previously setted notification. Which you are getting.

Solutions:

When you open the app then in "didFinishLaunchingWithOptions" method of AppDelegate, call below method.

-(void)removeAllLocalNotification
{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
}

So that, you will remove all previously set notification.

But, before doing above thing: You need to take care that, you have to call the above method only once. Not every time when app launch.

You can do it in following way:

Create one BOOL variable and store it in NSUserDefault. Now, when app open then check it's value from NSUserDefault. If it is FALSE, then call above method and set it's value to TRUE and set into NSUserDefault.

Now, when you re-open the app then you will get it's value as TRUE so at this time, you don't need to call above method. So that, your current set notification not removed.

Hope, you got the entire things.

Happy Coding.

Cheers!

like image 182
Nishant B Avatar answered Oct 24 '22 03:10

Nishant B