取消 iPhone 中的重复 UILocalNotification

发布于 2024-12-01 02:57:05 字数 1246 浏览 0 评论 0原文

我使用这个链接来设置重复UILocalNotification 和我的代码运行成功,但问题是,即使我删除我的应用程序,也会弹出警报是否有任何方法可以实际取消重复 UILocalNotification

这是我用来设置重复的代码1 分钟后

- (void)alertSelector:(NSString *)AlertTitle WithFiringTime:(NSDate *)date{
    UILocalNotification *localNotification = [[[UILocalNotification alloc] init] autorelease];
    if (!localNotification) 
        return;
    [localNotification setFireDate:date];
    [localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
    NSDictionary *data = [NSDictionary dictionaryWithObject:date forKey:@"payload"];
    [localNotification setUserInfo:data];
    [localNotification setAlertBody:AlertTitle];
    [localNotification setAlertAction:@"View"];
    [localNotification setHasAction:YES];      
    localNotification.repeatInterval = NSMinuteCalendarUnit;      
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

使用下面的代码取消 UILocalNotification,但它取消了所有 UILocalNotification,我只想取消 1 分钟后弹出的 UILocalNotification,请重复 UILocalNotification

[[UIApplication sharedApplication] cancelAllLocalNotifications];

提前谢谢

i used this Link to set Repeat UILocalNotification and my code run successfully but the problem is that even when i delete my Application , alerts are poping up is there is any way to cancel the repeat UILocalNotification pragmatically

this is the code which i am using to set repeat UILocalNotification after 1 minute

- (void)alertSelector:(NSString *)AlertTitle WithFiringTime:(NSDate *)date{
    UILocalNotification *localNotification = [[[UILocalNotification alloc] init] autorelease];
    if (!localNotification) 
        return;
    [localNotification setFireDate:date];
    [localNotification setTimeZone:[NSTimeZone defaultTimeZone]];
    NSDictionary *data = [NSDictionary dictionaryWithObject:date forKey:@"payload"];
    [localNotification setUserInfo:data];
    [localNotification setAlertBody:AlertTitle];
    [localNotification setAlertAction:@"View"];
    [localNotification setHasAction:YES];      
    localNotification.repeatInterval = NSMinuteCalendarUnit;      
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

with the code below i cancel the UILocalNotification but it cancel all the UILocalNotification and i want to cancel only the UILocalNotification which is poping up after 1 minute , Repeat UILocalNotification

[[UIApplication sharedApplication] cancelAllLocalNotifications];

Thankx in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月苍老的讽刺 2024-12-08 02:57:05

您应该保留您希望在将来某个时刻取消的通知,并使用 cancelNotification: 方法,而不是使用 cancelAllLocalNotifications

cancelNotification: 允许您取消特定通知,但相当明显的警告是您必须保留要取消的通知对象!

Instead of using cancelAllLocalNotifications you should retain the notification you wish to cancel at some point in the future and use the cancelNotification: method.

cancelNotification: lets you cancel specific notifications, but the fairly obvious caveat is you must keep the notification objects you wish to cancel hanging around!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文