aznelite89 aznelite89 - 1 year ago 318
iOS Question

Correct way to retrieve token for FCM - iOS 10 Swift 3

i had implement Firebase with FirebaseAuth/FCM etc and did sent notification successfully through Firebase Console.

However i would need to push the notification from my own app server.

i am wondering below which way is correct way to retrieve the registration id for the device:-

1) retrieve registration id token from didRegisterForRemoteNotificationWithDeviceToken

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
var token = ""

for i in 0..<deviceToken.count {
token += String(format: "%02.2hhx", arguments: [deviceToken[i]])

print("Registration succeeded!")
print("Token: ", token)


2) Retrieve Registration token from firebase (Based on Firebase document which retrieve the current registration token)

let token = FIRInstanceID.instanceID().token()!

i was using the first way, the push notification is not being received even the registration id is stored on my app server database accordingly and i get this CURL session result :-


i had also tried the second way and get fatal error while running the app as below:-
enter image description here

appreciated if anyone could point me the right way, thanks!

Answer Source

try this

let credential = FIRFacebookAuthProvider.credential(withAccessToken;FBSDKAccessToken.current().tokenString)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download