Remove a local notification from iPhone by Date - iphone

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];

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.

Local Notification (repeat) fired after new install of app

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.

How can I temporarily disable all local notification scheduled by my iPhone app?

Is there any method to temporarily disable all local notifications created by an iPhone app? I need to re enable them all with respect to a condition. my requirement is if the user turned off the notification button on my app , then no more notifications is shown.If he turned it on then all notifications should be shown. Any idea?
You can get all scheduled notifications and save them in shared preferences for example.
[[UIApplication sharedApplication] scheduledLocalNotifications];
Then cancel all notifications:
- (void)cancelLocalNotification:(UILocalNotification *)notification
If user activate notifications again, you can reschedule them again.
You can use "cancelAllLocalNotifications" method and When User turn it On you can set again All notification for it.

How can I update the [[UIApplication sharedApplication] scheduledLocalNotifications] array?

This may be more of a question regarding how to update arrays in general, but I have an app that is utilizing UILocalNotifications, and I want to allow users to select the notifications they have set, and edit them.
So what could I do to update an object at an index?
[[[UIApplication sharedApplication] scheduledLocalNotifications] ??];
Thanks for any help!
Once you get the UILocalNotification object, you can "reschedule" it by canceling the old notification with:
[[UIApplication sharedApplication] cancelLocalNotification:aNotification];
and scheduling a new one:
[[UIApplication sharedApplication] scheduleLocalNotification:aNotification];
You can not able to edit an already existing notification.
But you can able to cancel it by using cancelLocalNotification: and create a fresh notification.

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