0

In one of my app, I want to show the local notification and once it's shown in notification center, I want to updated it's content.

Is it possible in Swift ?

Thanks,

HP.

2 Answers2

0

Not exactly. But you can remove it and add an new one with the new text.

Tobi Nary
  • 4,566
  • 4
  • 30
  • 50
0

Here's the solution for other visitors:

https://developer.sinnerschrader-mobile.com/ios-how-to-remove-a-notification-programmatically-from-ios-notification-center/582/

Using NSKeyedArchiver, I archived my old local notification to one path and when I wanted to remove it, I deleted it from that location.

It's working fine.

Edited :

1)Cache UILocalNotificaiton using NSKeyedArchiver

NSString *archivePath = [self cachePathWithKey:key];
[NSKeyedArchiver archiveRootObject:notification toFile:archivePath];

2) Show Notification

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

3) Remove Notification Whenever you want to remove it.

NSString *archivePath = [self cachePathWithKey:key];

UILocalNotification *cachedNotification = [self notificationForKey:key];
if (cachedNotification == nil) {
    return NO;
}

[[UIApplication sharedApplication] cancelLocalNotification:cachedNotification];

[[NSFileManager defaultManager] removeItemAtPath:archivePath error:nil];

You can use this library also as I've used that one only.

https://github.com/sinnerschrader-mobile/s2m-toolbox-ios

Copy LocalNotificationHelper Folder in your project and User removeNotificationForKey and showNotification methods.

Thanks,

HP.

  • Link is not working "Error establishing a database connection". Also, please add the key details of the solution in the post itself, so that it is still possible to understand the solution without the link. – fishinear Jan 30 '16 at 14:48
  • Ok Sure. I'll do that. – Hemang Pandya Jan 31 '16 at 06:09