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

Swift 3 + Firebase 4.0.4 :

static var FirebaseToken : String? {
    return InstanceID.instanceID().token()
}

The recommended way by Firebase:

let token = Messaging.messaging().fcmToken

Reference : Setting Up a Firebase Cloud Messaging Client App on iOS


The tokenRefreshNotification function doesn't always get called when launching the app.

However, when placing the code inside the regular didRegisterForRemoteNotificationsWithDeviceToken delegate function, I can get the token every time:

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    if let refreshedToken = InstanceID.instanceID().token() {
        print("InstanceID token: \(refreshedToken)")
    }
}

(Swift 3 + Firebase 4.0.4)