Never Forget to define your REVERSED_CLIENT_ID (provided in GoogleService info.plist file) to your project target ->Info->URLschema .
//Add your APNS certificate in the application created in Firebase.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
UIApplication.shared.registerUserNotificationSettings(settings)
UIApplication.shared.registerForRemoteNotifications()
NotificationCenter.default.addObserver(self,selector: #selector(self.tokenRefreshNotification),
name: NSNotification.Name.firInstanceIDTokenRefresh,
object: nil)
FIRApp.configure()//this line is must to configure plist with application
return true
}
In Applegate you will have to write below methods:
func tokenRefreshNotification(notification: NSNotification) {
if let refreshedToken = FIRInstanceID.instanceID().token() {
print(“InstanceID token: \(refreshedToken)”)
}
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFcm()
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.sandbox)
//App is in sandbox mode .When App is live APNS token Type would change.
}
func connectToFcm() {
FIRMessaging.messaging().connect { (error) in
if error != nil {
print(“Unable to connect with FCM. \(error)”)
} else {
print(“Connected to FCM.”)
}
}
}
func applicationDidBecomeActive(_ application: UIApplication) {
connectToFcm()
}