UILocalNotification not showing in the lock screen

夙愿已清 提交于 2019-12-13 00:41:10

问题


Is there any special parameters an UILocalNotification has to have in order to show on the lock screen like the Facebook Messenger messages? My notification does appear on the notification center under "notifications". I think the behaviour is similar to the AppStore notifications in where they are only shown as a notification but the user is never alerted.


回答1:


You probably didn't add .Badge when you did your registerUserNotificationSettings. You should have

let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories)
application.registerUserNotificationSettings(settings)



回答2:


You have to take permission for show the notification on lock screen ! once look at the code in Appdelegate.m

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let notificationCategory = UIMutableUserNotificationCategory()
let categories = Set<UIUserNotificationCategory>(arrayLiteral: notificationCategory)
let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: categories)
application.registerUserNotificationSettings(settings)
return true 
}


来源:https://stackoverflow.com/questions/26050751/uilocalnotification-not-showing-in-the-lock-screen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!