U23r
U23r

Reputation: 1703

Cannot fin 'InstanceID' and 'InstanceIDTokenHandler' on swift project after updated Firebase

I'm with an old project that needed to update Firebase, so I did. After that, I get two errors and I can't understand how to solve them. Could anyone help me with this, please?

File1.swift:

func token(withAuthorizedEntity authorizedEntity: String, scope: String, options: [AnyHashable: Any]? = nil, handler: @escaping InstanceIDTokenHandler) {
    
}

error: Cannot find type 'InstanceIDTokenHandler' in scope

File2.swift

func checkDeviceToken() {
    let hasDeviceToken: Bool      =  self.devicesTokenUseCase.hasDeviceToken()
    let dontHaveDeviceToken: Bool = !hasDeviceToken

    InstanceID.instanceID().instanceID { (result, _) in
        if let result = result {
            let isNotSameToken: Bool = !self.devicesTokenUseCase.isSameDeviceToken(deviceToken: result.token)

            if hasDeviceToken && isNotSameToken {
                self.updateDeviceToken(token: result.token)
            } else if dontHaveDeviceToken {
                self.sendDeviceToken(token: result.token)
            }
        } else {
            self.checkDeviceToken()
        }
    }
}

error: Cannot find 'InstanceID' in scope

Upvotes: 0

Views: 1673

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599541

Instance IDs have been deprecated, and removed in recent SDK release.

The new tokens that FCM uses to target messages are called Installation IDs. You can get the current token for your app instance by calling Messaging.messaging().token.

After you get the token, you can treat it the same as before.

Upvotes: 6

Related Questions