当应用程序在后台时,iOS UILocalNotification不显示 [英] iOS UILocalNotification not being displayed while app in background

查看:98
本文介绍了当应用程序在后台时,iOS UILocalNotification不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FIXED —好,发现它是什么,有一个错误 [[UIApplication sharedApplication] cancelAllLocalNotifications]; 被触发时,我没有预料到。

FIXED — Ok, found what it was, there was an errant [[UIApplication sharedApplication] cancelAllLocalNotifications]; being fired when I wasn't expecting it.

好,有你的问题。

感谢大家的帮助,对不起,它只是愚蠢的编码综合征。

Thanks for the help everyone, sorry to have it turn out to just be dumb coder syndrome.

我已经建立了我的本地通知,如下:

I've built out my local notification like so:

- (void)scheduleNotification {
    [[UIApplication sharedApplication] cancelAllLocalNotifications];
    Class cls = NSClassFromString(@"UILocalNotification");
    if (cls != nil) {
        UILocalNotification *notif = [[cls alloc] init];
        NSLog(@"%@", [NSDate date]);
        notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];

        notif.alertBody = NSLocalizedString(@"Hello.", nil);

        [[UIApplication sharedApplication] scheduleLocalNotification:notif];
        NSLog(@"Notification scheduled at %@", notif.fireDate);
        [notif release];
    }
}


$ b $ p

正如预期的那样,我的调试日志输出正确的fireDate 10秒在将来。如果我不离开我的应用程序,我会得到一个成功的应用程序:didReceiveLocalNotification:回调。

如果我按下按钮来安排此通知,并按Home按钮将其放在后台。如果我这样做,通知不会激活,我从来没有从操作系统获得警报视图。

The hiccup here is if I push the button to schedule this notification and hit the home button to put it in the background. If I do this, the notification never fires and I never get an alert view from the OS.

我错过了明显的事情吗?我在这里和苹果文档上下翻看,觉得我错过了一些明显的东西。

Did I miss something obvious here? I've looked up and down here and the Apple docs and feel I've missed something obvious.

任何帮助将非常感谢。感谢。

Any help would be greatly appreciated. Thanks.

推荐答案

好的,发现它是什么,有一个错误[[UIApplication sharedApplication] cancelAllLocalNotifications];在进入背景时发送。

Ok, found what it was, there was an errant [[UIApplication sharedApplication] cancelAllLocalNotifications]; being sent when entering the background.

这篇关于当应用程序在后台时,iOS UILocalNotification不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆