Rex
Rex

Reputation: 41

flutter 2 fcm ios apn issue

The firebase FCM is not working for me in flutter 2.2.2, am trying to implement push notification in my ios app and am getting this error :

8.3.0 - [Firebase/Messaging][I-FCM002022] APNS device token not set before retrieving FCM Token for Sender ID '*************'. Notifications to this FCM Token will not be delivered over APNS.Be sure to re-retrieve the FCM token once the APNS device token is set.

It’s been one month since this problem occurred.

I followed the step in this article and article

the push notifications works fine in Android the problem is with the iOS

this is my AppDelegate.swift

import UIKit
import Flutter
import Firebase

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
// Use Firebase library to configure APIs
FirebaseApp.configure()
if #available(iOS 10.0, *) {
  // For iOS 10 display notification (sent via APNS)
  UNUserNotificationCenter.current().delegate = self

  let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
  UNUserNotificationCenter.current().requestAuthorization(
    options: authOptions,
    completionHandler: { _, _ in }
  )
} else {
  let settings: UIUserNotificationSettings =
    UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
  application.registerUserNotificationSettings(settings)
}

application.registerForRemoteNotifications()

    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Upvotes: 1

Views: 483

Answers (1)

Sayan Chakraborty
Sayan Chakraborty

Reputation: 76

you have to add

Messaging.messaging().apnsToken = deviceToken

before

return super.application(application, didFinishLaunchingWithOptions: launchOptions)

Upvotes: 0

Related Questions