Receive local notifications after deleting and reinstalling an iphone app

主宰稳场 提交于 2019-12-04 17:36:49

问题


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?


回答1:


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!



来源:https://stackoverflow.com/questions/14257678/receive-local-notifications-after-deleting-and-reinstalling-an-iphone-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!