如何获取代币价值?我正在使用Firebase,swift3,xcode8
令牌值为零。
import UIKit
import Firebase
class TestViewController: UIViewController {
// FCM Messaging test
override func viewDidLoad() {
super.viewDidLoad()
let token = FIRInstanceID.instanceID().token()
print("Token is (token)")
}
控制台日志"Token is nil"
我也有同样的问题,我通过添加以下代码解决了它
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.tokenRefreshNotification), name: kFIRInstanceIDTokenRefreshNotification, object: nil)
}
然后
func tokenRefreshNotification(notification: NSNotification) {
// NOTE: It can be nil here
if let token = FIRInstanceID.instanceID().token() {
refreshedToken = token
print("InstanceID token: (refreshedToken)")
}
}
检查控制台(如果获取令牌(。