Firebase InstanceId unresolved identifier swift4

♀尐吖头ヾ 提交于 2020-05-29 05:38:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!