Local Notification (repeat) fired after new install of app - iphone

in my app I am using local notifications and often they have a repeat interval set.
The problem is, when the user deletes the app and reinstalls it, the repeat notifications start firing again.
Is there a fix for this problem? Will the following suggestion from another user work? :
you can use [[UIApplication sharedApplication] cancelAllLocalNotifications]; only at first launch, so that "old" notification will be cancelled....(I haven't tried that)
Thanks a lot!

you can use [[UIApplication sharedApplication]
cancelAllLocalNotifications]; only at first launch, so that "old"
notification will be cancelled...
This is not your solution. This will cancel all your already scheduled notification every time when your didFinishLaunching method will called. So before applying above solution there should be one more check. Store a value in NSUserDefauls for checking that you are installing application again after deleting.
if(![[NSUserDefaults standardUserDefaults]objectForKey:#"Notification"]){
[[UIApplication sharedApplication] cancelAllLocalNotifications]
[[NSUserDefaults standardUserDefaults]setBool:Yes ForKey:#"Notification"];
}
This will prevent from canceling all notifications every time.

Related

How to remove Single Remote notification in iphone

I am developing game which have support of server side push notification of score and winning notification, User game request.
All is working fine with notification read and response store to device side. But when notification is pushing to notification center. when i click on notification at that time it remove all the push notification from notification center with following code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
But i want to remove selected remote notification from notification center.
Is there any way to remove single remote notification.Please help me.
Thanks in advance.
To cancel local notifications
If you have the means to obtain a reference to the specific UILocalNotification instance you want to cancel, you can call cancelLocalNotification: on it.
Try traversing all scheduled notifications in order to obtain that reference by going through:
NSArray *scheduledNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
To cancel remote notifications
This is entirely up to the server, can't be done without proper API on the server's side.

How to cancel all local notifications when app is deleted from background not from device

I want to cancel all local notifications when app deleted from background, not from Device.
I know this is
[[UIApplication sharedApplication] cancelAllLocalNotifications];
but my Question is where should i pass it to fire event when application terminates from background.
I called inside applicationWillTerminateFromBackground but it is not working.
You could simply check to see if the app is in the background, and if it is, not fire the notifications.

Remove a local notification from iPhone by Date

there is the possibility of a LocalNotification on the iPhone to load on a date?
My problem is that I create an event for the notification but i release the object after creation.
Or can I just create a new Object with the same data to delete my Notification?
sorry for my english...
scheduledLocalNotifications will give you the list of all scheduled notifications and use
- (void)cancelLocalNotification:(UILocalNotification *)notification
or you can cancel them all using:
[[UIApplication sharedApplication] cancelAllLocalNotifications];

Piling up UILocalNotifications

I'm developping an app that sends tips to users every five minutes through UILocalNotifications. The problem is that if you don't use your phone for a while, the notifications pile up and when you unlock the phone, you have to dismiss them one after the other, which can become quite annoying if you haven't used the phone for quite a while. Clicking the action button on the Alert sends you back to the application but even then, you still have to go through all the notifications.
Is there any means of dismissing all the notifications that have already been fired with a single click ?
Thanks for your help.
Miky Mike
Well, actually, I realize I made a mistake.
In order to cancel all the UIlocalNotifications at one, I just have to create this simple method : one line of code is enough :
- (void)application:(UIApplication *)app didReceiveLocalNotification :(UILocalNotification *)notification {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
and there you are. Thanks anyway.
Before scheduling the next alarm you better to cancel all the previous notifications and then set the new one,
UIApplication* app = [UIApplication sharedApplication];
NSArray* oldNotifications = [app scheduledLocalNotifications];
// Clear out the old notification before scheduling a new one.
if ([oldNotifications count] > 0)
[app cancelAllLocalNotifications];

sample code for canceling the local notification in iphone

Sample code for canceling the local notification.
I am having a application which sets a local notification and now i want to cancel one of the local notification set the by the application can someone provide the sample code for the same
Cancel all local notifications with this code:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
(you actually just need the middle line.
Cancel one local notification with this line of code:
[[UIApplication sharedApplication] cancelLocalNotification:theNotification];
where theNotification is a UILocalNotification object, so in order to cancel a specific notification you need to hold on to it's UILocalNotification.
You can find more stuff in apple's documentation: http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html