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 UILocalNotification
has. 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
- Get the array of scheduled notifications
- Create a mutable copy
- Create a new notification based on the one you want to modify
- Insert the notification
- Remove the old notification
- Set this new array as the list of scheduled notifications
You may of course combine 4.+5. by replacing the object.
Related Topics
React-Native Run-iOS Can Not Find Any Simulator
Deferredlocationupdatesavailable Returns No in iOS 10
How to Disable 4 Finger Gestures on iPad
Is There a Simple Way to Edit/Modify a Uilocalnotification
Customize Apps Gallery in Appstore Page
What's the State of Developing iOS Apps in Linux
Xmlparser.Sharedparser.Decode() in Swift3
Setting Multiple Times for Notifications in Swift
Add Rounded Corners to All Uiimageviews
Apple Llvm 6.0 Error: Clang Failed with Exit Code -1
How to Enumerate All Nodes in a Sprite Kit Scene
How to Disable iPhone 6 Native Resolution
Flutter on iOS: Fatal Error: Module 'Cloud_Firestore' Not Found
How to Get File Name in Uiimagepickercontroller with Asset Library
How to Integrate Crashlytics into an iOS Framework Target
How to Get a Crash Log Due to Expiration of Provisioning Profile