取消 iPhone 中的重复 UILocalNotification
我使用这个链接来设置重复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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该保留您希望在将来某个时刻取消的通知,并使用
cancelNotification:
方法,而不是使用cancelAllLocalNotifications
。cancelNotification:
允许您取消特定通知,但相当明显的警告是您必须保留要取消的通知对象!Instead of using
cancelAllLocalNotifications
you should retain the notification you wish to cancel at some point in the future and use thecancelNotification:
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!