问题
I have recently updated My SWIFT applications pod file, And because of that firebase version is now updated to a 5.2. Which now gives me following error while getting a device instance id.
let tokenId = InstanceID.instanceID().token()
error: Use of unresolved identifier 'InstanceID'
Previously this code was working fine and I was getting Application's Instance Id.
Following is content of my pod file.
# Uncomment the next line to define a global platform for your project
# platform :ios, '11.2'
target 'FirebaseChat' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for FirebaseChat
pod 'Firebase/Database'
pod 'Firebase/Auth'
pod 'Firebase/Storage'
pod 'UnderLineTextField', '~> 2.0'
pod 'Alamofire'
pod 'TCPickerView'
pod 'Toast-Swift', '~> 3.0.1'
pod 'IQKeyboardManagerSwift'
end
Any suggestions will be helpful. Thank You.
回答1:
You should import FirebaseInstanceID
import FirebaseInstanceID
回答2:
Firebase made changes for token in FirebaseInstanceID update so now they changed syntaxes to get token
Try this
InstanceID.instanceID().instanceID(handler: { (result, error) in
if let error = error{
print("Error fetching remote instange ID(Token): \(error)")
}else if let result = result{
print("Remote instance ID token: \(result.token)")
}
})
and import
import FirebaseInstanceID
回答3:
Syntax changed in latest update
if let refreshedToken = FIRInstanceID.instanceID().token() {
print("InstanceID token: \(refreshedToken)")
}
来源:https://stackoverflow.com/questions/50760222/firebase-instanceid-unresolved-identifier-swift4