UILocalNotification 文本显示在通知中心后如何更改?
How to Change UILocalNotification Text after it's shown in notification center?
在我的一个应用程序中,我想显示本地通知,一旦它显示在通知中心,我想更新它的内容。
Swift可以吗?
谢谢,
HP.
不完全是。但是您可以删除它并添加一个带有新文本的新文本。
以下是其他访客的解决方案:
使用 NSKeyedArchiver,我将旧的本地通知存档到一个路径,当我想删除它时,我从那个位置删除了它。
一切正常。
已编辑:
1)使用 NSKeyedArchiver 缓存 UILocalNotificaiton
NSString *archivePath = [self cachePathWithKey:key];
[NSKeyedArchiver archiveRootObject:notification toFile:archivePath];
2) 显示通知
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
3) 随时删除通知。
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];
你也可以使用这个库,因为我只用过那个。
https://github.com/sinnerschrader-mobile/s2m-toolbox-ios
复制项目中的 LocalNotificationHelper 文件夹和用户 removeNotificationForKey 和 showNotification 方法。
谢谢,
HP.
在我的一个应用程序中,我想显示本地通知,一旦它显示在通知中心,我想更新它的内容。
Swift可以吗?
谢谢,
HP.
不完全是。但是您可以删除它并添加一个带有新文本的新文本。
以下是其他访客的解决方案:
使用 NSKeyedArchiver,我将旧的本地通知存档到一个路径,当我想删除它时,我从那个位置删除了它。
一切正常。
已编辑:
1)使用 NSKeyedArchiver 缓存 UILocalNotificaiton
NSString *archivePath = [self cachePathWithKey:key];
[NSKeyedArchiver archiveRootObject:notification toFile:archivePath];
2) 显示通知
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
3) 随时删除通知。
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];
你也可以使用这个库,因为我只用过那个。
https://github.com/sinnerschrader-mobile/s2m-toolbox-ios
复制项目中的 LocalNotificationHelper 文件夹和用户 removeNotificationForKey 和 showNotification 方法。
谢谢,
HP.