我正在制作一个需要向用户发送通知的应用程序。到目前为止,我已经在 App Delegate 中注册了通知:
let notifTypes: UIUserNotificationType = [.Alert, .Badge, .Sound]
let notifSettings = UIUserNotificationSettings(forTypes: notifTypes, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notifSettings)
然后调用以下代码在 View Controller 中发送通知:
let localNotification: UILocalNotification = UILocalNotification()
localNotification.alertAction = "Testing notifications on iOS8"
localNotification.alertBody = "Here is a notification"
localNotification.fireDate = NSDate(timeIntervalSinceNow: 5)
localNotification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
如果我下拉通知中心面板,会显示通知,但如果我不在应用程序中,则不会显示横幅,如果手机处于关机状态,锁定屏幕上不会显示通知。如果我不在应用程序之外,如何让通知显示在锁定屏幕上/作为横幅显示?
最佳答案
当通知触发时,您以用户角色看到的内容取决于您在首选项中的设置。您需要转到“设置”并将此应用配置为显示横幅并在锁定屏幕中显示通知。
我还建议,出于测试目的,您应该将通知安排在稍晚的时间间隔。你说的是 NSDate(timeIntervalSinceNow: 5)
- 这不是让你自己离开应用程序的时间!通知可能会在您仍在应用程序中时触发——在这种情况下不会出现横幅。
关于ios - 不显示本地通知横幅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31487410/