如何向用户显示通知,即使应用未运行或用户强制关闭。 如果我的应用程序是打开的或在后台我收到通知。但如果我强行关闭我的应用程序,我不会在xcode 8.3和swift 3 iOS
中收到通知if #available(iOS 10.0, *) {
let center = UNUserNotificationCenter.current()
//center.delegate = self
center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in
if error == nil{
UIApplication.shared.registerForRemoteNotifications()
}
}
}
else {
UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
UIApplication.shared.registerForRemoteNotifications()
}
通过这种方式我正在注册通知