我正在使用远程通知来唤醒我的应用程序并有条件地触发UILocalNotification。iOS UILocalNotification仅在应用程序未运行时发出声音(无警报)
我发现如果这个通知是在应用程序没有运行时触发的,我得到的只是通知声音(没有警报/通知)。如果应用程序在后台,它会按预期工作。
注册为远程通知中的AppDelegate:
let settings = UIUserNotificationSettings(forTypes: (.Badge | .Sound | .Alert), categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
创建/ UILocalNotification的烧成(作为didReceiveRemoteNotification
结果)
var notification = UILocalNotification()
notification.alertTitle = "My App"
notification.alertBody = "Hello World!"
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().presentLocalNotificationNow(notification)
据我可以从文档告诉,通知的行为,当该应用程序在后台,根本不运行应该是相同的。
当系统提供本地通知时,可能会发生几种情况,具体取决于应用程序状态和通知类型。如果应用程序不是最前面并且可见,则系统显示警报消息,标记应用程序并播放声音 - 无论通知中指定了什么内容。如果通知是警报,并且用户点击操作按钮(或者,如果设备被锁定,则拖动打开操作滑块),则应用程序被唤醒或启动。
来源:UILocalNotification Documentation
见识到了什么是怎么回事,非常感谢!
运行设置应用程序并转到您的应用程序页面。检查您的应用的通知设置。 – rmaddy
我已验证应用程序的通知设置已启用。正如我所提到的,当应用程序处于后台时,所有功能都可以正常工作,但不是在我明确关闭它时(通过将其滑开) – Rhinon