На Push-уведомление от возможностей и Добавить UserNotification кадра работы в BuildPhase в AppDelegate добавить метод делегата UNUserNotificationCenterDelegate
import UserNotifications
В didFinishingLaunching ...
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 {
// Fallback on earlier versions
}
Добавить эти методы
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let deviceTokenString = deviceToken.reduce("", {$0 + String(format: "%02X", $1)})
print(deviceTokenString)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("i am not available in simulator \(error)")
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
}
Надавите уведомление о возможностях .. –
работает с iOS 10. Но не работает на iOS 9.3.2. – vikash1307
установить цель развертывания до 9 с iOS 10, Xcode 8, он будет работать на устройстве с iOS 9. –