Попробуйте это, это работает для меня (код Swift 4)
Запрос на разрешение
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
self.setupFirebase(applicatin: application)
}
Настройка Firebase registerUserNotificationSettings
func setupFirebase(applicatin:UIApplication)
{
if #available(iOS 10.0, *) {
let authOptions : UNAuthorizationOptions = [.alert, .badge , .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_,_ in })
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
// For iOS 10 data message (sent via FCM)
// FIRMessaging.messaging().remoteMessageDelegate = self
} else {
let notificationtype :UIUserNotificationType = [UIUserNotificationType.alert,UIUserNotificationType.badge,UIUserNotificationType.sound]
let notificationsettings = UIUserNotificationSettings(types: notificationtype, categories: nil)
applicatin.registerUserNotificationSettings(notificationsettings)
}
applicatin.registerForRemoteNotifications()
}
Получение токена устройства
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
guard InstanceID.instanceID().token() != nil
else {
return
}
if let refreshedToken = InstanceID.instanceID().token()
{
print("InstanceID token: \(refreshedToken)")
}
}
В случае ошибки
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Filed to register : \(error.localizedDescription)")
}