gpt4 book ai didi

ios - 关闭已经传送的 UILocalNotification?

转载 作者:技术小花猫 更新时间:2023-10-29 11:15:17 25 4
gpt4 key购买 nike

这有可能吗? UIApplication's scheduledLocalNotifications 似乎没有返回已经发送到用户通知中心的通知,所以我认为这可能是设计使然,但我找不到任何有据可查的证据。

有人知道吗?

谢谢!

编辑:发现这个:

You can cancel a specific scheduled notification by calling cancelLocalNotification: on the application object, and you can cancel all scheduled notifications by calling cancelAllLocalNotifications. Both of these methods also programmatically dismiss a currently

此处:http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html

但是,如果 scheduledLocalNotifications 没有给我已发送的通知,我如何获得对已发送通知的引用?

编辑 2:

这是我在注册一些通知后尝试做的事情:

UIApplication *app = [UIApplication sharedApplication];

for (UILocalNotification *localNotification in app.scheduledLocalNotifications)
{
if (someCondition) {
[app cancelLocalNotification:localNotification];
}
}
}

问题是,一旦它们被交付,它们就不再处于“scheduledLocalNotifications”中。

最佳答案

您可以通过将新创建的通知添加到您自己的 NSMutableArray 通知并检查该数组而不是 app.scheduledLocalNotifications 来解决此问题。像这样:

NSMutableArray 添加到您的 Viewcontrollers .h 文件中:

NSMutableArray *currentNotifications;

在启动 ViewController 时启动它

currentNotifications = [[NSMutableArray alloc] init];

发起通知时,也将其添加到您的数组中:

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

稍后当您想要取消该通知时,请改为在您的数组中查找它。同时将它从你的数组中删除:

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

关于ios - 关闭已经传送的 UILocalNotification?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10652274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com