Correct way to retrieve token for FCM - iOS 10 Swift 3 : <p>i had implement Firebase with FirebaseAuth/FCM etc and did sent notification successfully through Firebase Console. </p>

<p>However i would need to push the notification from my own app server.</p>

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

<p><strong>1) retrieve registration id token from didRegisterForRemoteNotificationWithDeviceToken</strong></p>

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

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

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

}
</code></pre>

<p><strong>2) Retrieve Registration token from firebase</strong> (Based on Firebase document which retrieve the current registration token)</p>

<pre><code>let token = FIRInstanceID.instanceID().token()!
</code></pre>

<p>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 :-</p>

<pre><code>{"multicast_id":6074293608087656831,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
</code></pre>

<p>i had also tried the second way and get fatal error while running the app as below:-
<a href="https://i.stack.imgur.com/ZeQ9U.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZeQ9U.png" alt="enter image description here"></a></p>

<p>appreciated if anyone could point me the right way, thanks!</p>
