Ios 本地通知横幅不';不出现

Ios 本地通知横幅不';不出现,ios,swift,notifications,Ios,Swift,Notifications,我正在制作一个需要向用户发送通知的应用程序。到目前为止,我已在App Delegate中注册了通知: let notifTypes: UIUserNotificationType = [.Alert, .Badge, .Sound] let notifSettings = UIUserNotificationSettings(forTypes: notifTypes, categories: nil) UIApplication.sharedApplication().regis

我正在制作一个需要向用户发送通知的应用程序。到目前为止,我已在App Delegate中注册了通知:

let notifTypes: UIUserNotificationType = [.Alert, .Badge, .Sound]
    let notifSettings = UIUserNotificationSettings(forTypes: notifTypes, categories: nil)
    UIApplication.sharedApplication().registerUserNotificationSettings(notifSettings)
并调用以下代码在视图控制器中发送通知:

 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)
-这不是让你自己退出应用程序的时间!通知可能会在您仍在应用程序中时触发-在这种情况下,不会显示任何横幅

“如果手机关机,锁屏上不会显示通知”如果手机确实关机,锁屏上怎么会出现任何东西?