iOS:Firebase标记返回null [英] iOS: Firebase token returning null

查看:528
本文介绍了iOS:Firebase标记返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照官方的Firebase文档实施Firebase云消息传递。



我已经解决了启用了推送通知的证书和配置配置文件。我也安装了所有必要的框架(FirebaseMessaging,Firebase),使用CocoaPods,他们似乎工作正常。

在应用程序委托,我试图初始化Firebase云消息令牌与下面的代码。

  let token = FIRInstanceID.instanceID()。token()! 

我也将GCM设置为启用,并在GoogleService-Info中有一个GCM发件人ID值。



我得到的错误如下:


2016 -11-29 16:11:12.358 Firebasesample [3852:122151]启用了Firebase自动
屏幕报表。呼叫+ [FIRAnalytics
setScreenName:setScreenClass:]设置屏幕名称或覆盖
的默认屏幕类名称。要禁用自动屏幕报告功能,请在
Info.plist中将
标志FirebaseAutomaticScreenReportingEnabled设置为NO。

2016-11-29 16:11:12.419 :Firebase
消息传递设置不正确,无senderID。致命错误:意外地
发现零,同时展开一个可选值

感谢您的任何建议/帮助。已经在没有执行的评论中回答:

确保请按照 https://firebase.google.com/docs/上的设置指南进行操作在您的 didFinishLaunchingWithOptions 中添加以下方法(在 code> FIRApp.configure())。

  NotificationCenter.default.addObserver ,selector:#selector(tokenRefreshNotification(_ :)),name:NSNotification.Name.firInstanceIDTokenRefresh,object:nil)


$ b $当你的令牌刷新时,它会调用:
$ b $ pre $ func tokenRefreshNotification(_ notification:Notification){

gu ard let token = FIRInstanceID.instanceID()。token()else {
QL3(No firebase token,aborting registering device)
return nil
}

//注册你的令牌某处..
registerToken(令牌)
}


I am currently trying to implement Firebase Cloud Messaging by following the official Firebase documents.

I have settled the certificates and the provisioning profiles with Push Notifications enabled. I have also installed all the necessary frameworks(FirebaseMessaging,Firebase) using CocoaPods and they seem to work fine.

At the app delegate, I tried to initialize the Firebase cloud messaging token with the code below.

let token = FIRInstanceID.instanceID().token()!

I have also set GCM to enabled and there is a GCM sender id value in the GoogleService-Info.plist.

The error that I am getting is as follows:

2016-11-29 16:11:12.358 Firebasesample[3852:122151] Firebase automatic screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO in the Info.plist

2016-11-29 16:11:12.419: Firebase messaging not setup correctly, nil senderID. fatal error: unexpectedly found nil while unwrapping an Optional value

Thank you in advance for any advice/help.

解决方案

Was already answered in the comment without the implementation:

Make sure you follow the setup guide on https://firebase.google.com/docs/cloud-messaging/ios/client.

In your didFinishLaunchingWithOptions add the following method (after FIRApp.configure()).

NotificationCenter.default.addObserver(self, selector: #selector(tokenRefreshNotification(_:)), name: NSNotification.Name.firInstanceIDTokenRefresh, object: nil)

When your token is refreshed, it will call:

func tokenRefreshNotification(_ notification: Notification) {

    guard let token = FIRInstanceID.instanceID().token() else {
        QL3("No firebase token, aborting registering device")
        return nil
    }

    //register your token somewhere..
    registerToken(token)
}

这篇关于iOS:Firebase标记返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆