3

I use FirebaseInstanceID framework to fetch the token.

Current implementation is as below:

InstanceID.instanceID().token(withAuthorizedEntity: <GCM_SENDER_ID>, scope: "GCM", options: nil) { (token, error) in
}

My only requirement is of getting the token from Firebase for authentication purposes only.

The above implementation doesn't require adding GoogleService-Info.plist and any other frameworks.

The problem is, Google has deprecated GCM.

If I change scope from "GCM" to "FCM", it returns me an error 1001. Also If I change withAuthorizedEntity from <GCM_SENDER_ID> to <PROJECT_ID> it give me error 1001.

So, is there any way, using FCM just to fetch the token? As, I don't have any other requirements of sending Push notifications. TIA

KENdi
  • 7,576
  • 2
  • 16
  • 31
Dhruv
  • 2,153
  • 3
  • 21
  • 45

1 Answers1

2

I think you can try to migrate in right way using docs, but in this case, you should add GoogleService-Info.plist and required frameworks.

According to error code, problem is cause Firebase failing when fetching APNS token, it's mean you should set APNS token after receiving to get FCM token. You have two ways how to do it:

  1. Messaging.messaging().apnsToken = deviceToken inside func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {}
  2. Or using their Swizzling method

This answer will not help you fix it in way you want, but if you want fix it fast you can try this like option.

Hope it direct you in the right way.

Additional:

Avoid calling .getToken(authorizedEntity,scope) unless there is a need to enable multiple senders. Use instanceIDWithHandler: instead.

Similar question

Andrew
  • 1,456
  • 15
  • 23
  • I'm developing cocoa touch framework, and I don't have access to the method: `func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {}` – Dhruv Feb 15 '19 at 04:55
  • @Dhruv Like an option, you can inject `deviceToken` into the constructor of your framework object. But I don't know if it is acceptable for your environment. – Andrew Feb 15 '19 at 10:59
  • That won't make sense as we do not have any requirement of adding device token. – Dhruv Feb 18 '19 at 05:06