我需要停止或取消 UILocalNotification

发布于 2024-12-03 14:43:44 字数 1361 浏览 2 评论 0原文

我需要通过功能取消 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 技术交流群。

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

发布评论

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

评论(1

陪你到最终 2024-12-10 14:43:44

如果卡住意味着崩溃,那么遵循内存管理规则,您需要保留计时器。
当不再需要计时器时,使其无效并释放。

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.

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