UILocalNotification根本不起作用
我有一些UILocalNotification
非常恼人的问题。
在完成我几乎完成的应用程序时,我注意到无论我尝试了什么,都无法获得本地通知。
所以,我不是浪费时间,而是决定回到基础,看看能否让他们工作。
我创build了一个新的XCode基于视图的应用程序,并用-viewDidLoad
replace了-viewDidLoad
:
- (void)viewDidLoad { UILocalNotification * theNotification = [[UILocalNotification alloc] init]; theNotification.alertBody = @"Alert text"; theNotification.alertAction = @"Ok"; theNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10]; [[UIApplication sharedApplication] scheduleLocalNotification:theNotification]; }
但是,这也没有做任何事情。
我希望在启动应用程序10秒后看到一个通知,但没有出现。
另外,我在iPhone和模拟器上testing了这个。
我在这里错过了一些非常重要的事 ( 我已经通过苹果文档search,找不到为什么会发生这种情况 )
谢谢
UILocalNotification
仅在应用程序未运行(或在后台运行)时自动显示。 如果应用程序正在运行并且本地通知被触发,则UIApplicationDelegate
的- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
方法被调用,系统不显示任何内容(也不会播放声音)。 如果要显示通知,请在委托方法中自己创build一个UIAlertView
。
只是从我的个人冒险愚蠢的评论…
我有同样的问题,但我的问题是,我忘记了给alertBody分配一个值。 如果您没有设置alertBody,则通知将不会显示。
- fireDate必须是未来的时间。
- 应用程序必须在背景中运行,或closures。
-
还有一件事,不要忘记显示查询是否允许push,将下面的代码添加到AppDelegate中:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil]; [application registerUserNotificationSettings:settings]; } }
- pipe理核心数据iCloud事务日志
- 在swift中创build一个viewcontroller的单例
- 如何删除空的标题标题
- OpenCV色调曲线progrommatically
- didBeginContact :( SKPhysicsContact *)联系人未被调用
- 有没有办法认识到,该应用程序通过didFinishLaunchingWithOptions中的firebasedynamic链接安装?
- 我怎样才能保存这个数组的图像?
- 使用AVFoundation将章节信息添加到现有video
- iPhone的iOS如何添加一个UILongPressGestureRecognizer和UITapGestureRecognizer到相同的控制和防止冲突?