【问题标题】:Firebase sometimes get token NULL for ios devicesFirebase 有时会为 ios 设备获取令牌 NULL
【发布时间】:2019-05-30 16:44:58
【问题描述】:

我正在使用 Ionic 3 + Cordova 开发应用程序。在应用程序中,我已导入 Firebase 云消息库以向 android/ios 用户发送推送通知。问题是我已经在 Apple 开发人员面板上设置了认证,但有时我的应用程序上的函数“get_token()”返回的令牌仅对 IOS 用户返回 null,而且仅在某些时候返回。有时此函数返回正确的令牌,然后推送通知可以正常工作,但有时不能。

我已经尝试删除开发者苹果菜单上的所有认证。

get_token()函数在app.component.ts文件中,意思是用户打开应用时会生成token。

通过 firebase 服务器获取令牌:

try {
      const fcmToken = await this.fcm.getToken();
      Settings.push_token = fcmToken;
}

导入库:

import { FCM } from '@ionic-native/fcm';

这个 FCM 变量被传递给构造函数内部的 fcm 变量:

public fcm: FCM

我希望问题出在获取令牌的 firebase 工具上,因为我在互联网上没有找到任何解决方案。

【问题讨论】:

    标签: firebase push-notification ionic3 firebase-cloud-messaging apple-push-notifications


    【解决方案1】:

    我遇到了同样的问题,只有在平台准备好、fcm 已经连接时才通过调用 get_token() 来解决它:

    this.platform.ready().then(() => { // first, make sure platform is ready    
    
        this.fcm.getToken().then(token => { // save the token in the backend
    

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 2017-08-21
      • 1970-01-01
      • 2014-08-17
      • 1970-01-01
      • 2014-10-30
      • 2016-08-21
      • 2014-05-07
      • 2015-12-02
      相关资源
      最近更新 更多