【发布时间】:2015-06-19 23:54:02
【问题描述】:
我正在使用远程通知来唤醒我的应用并有条件地触发 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
非常感谢您深入了解这里发生的事情!
【问题讨论】:
-
运行设置应用程序并转到您的应用程序的页面。检查您应用的通知设置。
-
我已验证该应用的通知设置已启用。正如我所提到的,当应用程序在后台时,一切都按预期工作,但当我明确关闭它时(通过滑动它)
标签: ios apple-push-notifications uilocalnotification