UILocalNotification not showing in the lock screen

2019-08-09 06:27发布

问题:

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 
}


标签: ios ios8