Is There a Simple Way to Edit/Modify a Uilocalnotification

Is there a simple way to edit / modify a UILocalNotification

If the documentation is correct, you can't alter an already scheduled notification. The doc states for -scheduleLocalNotification::

[…] Because the operating system copies
notification, you may release it once
you have scheduled it.

The notification object is copied by the system and not accessible via any (public) method. So there's no other solution than canceling the notification.

how to edit local notifications in iphone sdk objective c

You cannot change an already scheduled notification.

You will have to cancel, and re-create it with the new data you need.

You can ask the current scheduled UILocalNotifications:

NSArray *scheduledNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];

Loop the array and do a check if its the notification you need to change:

for (UILocalNotification *notification in scheduledNotifications)
{
//Get the ID you set when creating the notification
NSDictionary *userInfo = notification.userInfo;
NSNumber *someValueYouGaveWhenCreatingCouldBeAnIdentifierOfAnObject = [userInfo objectForKey:@"someKey"];

if (someValueYouGaveWhenCreatingCouldBeAnIdentifierOfAnObject == someCheckYouHaveToDoHere)
{
[[UIApplication sharedApplication] cancelLocalNotification:notification];
//Re-create the localnotification with new data and the someValueYouGaveWhenCreatingCouldBeAnIdentifierOfAnObject

break;
}
}

Override an already displayed Local Notification

If the documentation is correct, you can't alter an already scheduled notification. The doc states for -scheduleLocalNotification::

[…] Because the operating system copies notification, you may release
it once you have scheduled it. The notification object is copied by
the system and not accessible via any (public) method. So there's no
other solution than canceling the notification.

Reference link

Dismiss an already delivered UILocalNotification?

You can solve this by adding your newly created notifications to your own NSMutableArray of notifications and check that array instead of app.scheduledLocalNotifications.
Something like this:

Add a NSMutableArray to your Viewcontrollers .h file:

NSMutableArray *currentNotifications;

Initiate it when initiating your ViewController

currentNotifications = [[NSMutableArray alloc] init];

When initiating a notification, also add it to your array:

UILocalNotification *notification = [[UILocalNotification alloc] init];
...
[currentNotifications addObject:notification];
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];

Later when you want to cancel that notification, look for it in your array instead.
Also remove it from your array:

for (UILocalNotification *notification in currentNotifications) {
if (someCondition) {
[[UIApplication sharedApplication] cancelLocalNotification:notification];
[currentNotifications removeObject:notification];
}
}

Can I change the message in a repeating UILocalNotification?

If you wanna change the message you can acces to the scheduledLocalNotifications array in your app delegate and modify the message, but to do that you need the app to be running. I think it's better to simply schedule different notifications with the different messages you want to show.

About the repeating interval the simple answers is no, you can't create your own repeating intervals. This is one of the many limitations that UILocalNotificationhas. Many apps (included mine) had solve the problem creating a queue of notifications. I explain that topic here

How i can change UserInfo in UILocalNotification?

Got the answer =)

int notifCount = [[[UIApplication sharedApplication] scheduledLocalNotifications] count];
for (int j = 0; j < notifCount; j++) {
UILocalNotification *notific = [[[UIApplication sharedApplication] scheduledLocalNotifications] objectAtIndex:j];
NSLog(@"notificBefore = %@ and j = %i", [notific.userInfo objectForKey:@"notif"], j+1);
if ([notific.userInfo objectForKey:@"notif"] != [NSString stringWithFormat:@"%i", j+1]) {
[[UIApplication sharedApplication] cancelLocalNotification:notific];
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%i", j+1] forKey:@"notif"];
[notific setUserInfo:infoDict];
NSLog(@"notificEnd = %@", [notific.userInfo objectForKey:@"notif"]);
[[UIApplication sharedApplication] scheduleLocalNotification:notific];
}
}

Override an already displayed Local Notification

If the documentation is correct, you can't alter an already scheduled notification. The doc states for -scheduleLocalNotification::

[…] Because the operating system copies notification, you may release
it once you have scheduled it. The notification object is copied by
the system and not accessible via any (public) method. So there's no
other solution than canceling the notification.

Reference link

Change text in already existing local notification

While it is not possible to directly edit the notification, you may

  1. Get the array of scheduled notifications
  2. Create a mutable copy
  3. Create a new notification based on the one you want to modify
  4. Insert the notification
  5. Remove the old notification
  6. Set this new array as the list of scheduled notifications

You may of course combine 4.+5. by replacing the object.



Related Topics



Leave a reply



Submit