我需要停止或取消 UILocalNotification
我需要通过功能取消 UILocalNotification,但如果我使用
[[UIApplication sharedApplication] cancelAllLocalNotifications];
我再次进入应用程序,但应用程序卡住了,它是计时器
UILocalNotification *local = [[UILocalNotification alloc] init];
local.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
local.timeZone = [NSTimeZone defaultTimeZone];
local.alertBody = @"";
local.alertAction = @"";
NSDictionary *customInfo =
[NSDictionary dictionaryWithObject:@"ABCD1234" forKey:@"yourKey"];
local.userInfo = customInfo;
[[UIApplication sharedApplication] scheduleLocalNotification:local];
[local release];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""message:@""delegate: self cancelButtonTitle:@"Close"otherButtonTitles: nil];
[alert show];
[alert release];
[self performSelector:@selector(myFunc) withObject:nil afterDelay:10.0];
startDate = [[NSDate date]retain];
// Create the stop watch timer that fires every 10 ms
myTime = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0
target:self
selector:@selector(updateTimer)
userInfo:nil
repeats:YES];
I need to cancel UILocalNotification by Function but if i use
[[UIApplication sharedApplication] cancelAllLocalNotifications];
i get to the app again but the app stuck , it's timer
UILocalNotification *local = [[UILocalNotification alloc] init];
local.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
local.timeZone = [NSTimeZone defaultTimeZone];
local.alertBody = @"";
local.alertAction = @"";
NSDictionary *customInfo =
[NSDictionary dictionaryWithObject:@"ABCD1234" forKey:@"yourKey"];
local.userInfo = customInfo;
[[UIApplication sharedApplication] scheduleLocalNotification:local];
[local release];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""message:@""delegate: self cancelButtonTitle:@"Close"otherButtonTitles: nil];
[alert show];
[alert release];
[self performSelector:@selector(myFunc) withObject:nil afterDelay:10.0];
startDate = [[NSDate date]retain];
// Create the stop watch timer that fires every 10 ms
myTime = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0
target:self
selector:@selector(updateTimer)
userInfo:nil
repeats:YES];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果卡住意味着崩溃,那么遵循内存管理规则,您需要保留计时器。
当不再需要计时器时,使其无效并释放。
If by stuck you mean crash, then following the memory management rules you need to retain your timer.
When there will be no need in timer anymore, invalidate and release it.