使用 Ionic 3 在 IOS 上下载应用程序时首次获取空令牌

Posted

技术标签:

【中文标题】使用 Ionic 3 在 IOS 上下载应用程序时首次获取空令牌【英文标题】:Getting null token on first time when the app is downloaded on IOS with Ionic 3 【发布时间】:2019-08-02 12:50:27 【问题描述】:

当我直接通过 USB 运行我的应用程序时,我可以正常获取令牌,但我已将应用程序上传到 testFlight,并且在我第一次在设备上运行应用程序时,我通过 Firebase 服务器获取了 null 令牌。如果我关闭应用程序并再次打开它,则会生成令牌并且推送通知正常工作。

我正在使用插件:Cordova-plugin-firebase

离子信息:

Ionic:

   ionic (Ionic CLI)  : 4.2.1 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.9

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 8.0.0, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 1.2.1, (and 15 other plugins)

System:

   Android SDK Tools : 26.1.1 (/Users/bruno/Library/Android/sdk)
   ios-deploy        : 1.9.2
   NodeJS            : v8.12.0 (/usr/local/bin/node)
   npm               : 6.4.1
   OS                : macOS
   Xcode             : Xcode 10.1 Build version 10B61

我试过了: - 下载应用程序 -> 打开它 -> 关闭它 -> 再次打开它并获取令牌

我已将令牌请求放在 app.components.ts 上,以便在应用打开时获取它。

solicitarToken()
    this.firebase.grantPermission();
    this.firebase.getToken()
    .then(token => 
      Settings.push_token = token;
      this.iniciarListenerDeNotificacoes();
      return token;
    ) 
    .catch(error => 
      console.error('Error getting token', error);
      return null;      
    );


  

这个请求放在构造函数的末尾。

我没有收到任何错误消息,只有空标记。我读过有时 Firebase 需要时间来生成令牌。我想在等待几毫秒,但我需要一个自信的解决方案,因为苹果分析应用程序有大约 3 天的延迟。

【问题讨论】:

【参考方案1】:

请使用 this.platform.ready 函数。

【讨论】:

我建议不要以反问的形式回答。他们有被误认为是澄清问题的风险,只要尚未达到评论特权,当然应该避免这种情况。因此,请edit 这是一个明显的答案,或者将其删除并等待您的评论权限来询问此问题以进行澄清。 好。现在,你能补充一些解释吗?很高兴了解它是如何工作的以及为什么它可以解决问题。

以上是关于使用 Ionic 3 在 IOS 上下载应用程序时首次获取空令牌的主要内容,如果未能解决你的问题,请参考以下文章

在 Ionic 应用程序中加载 Cloudfront 图像时出错 - iOS 9

Ionic v1 - 谷歌地图最初没有在 iOS 中加载

使用 Charles Proxy 在 iOS13 上下载 apple-app-site-association 文件失败

如何在 Ionic 2 或 3 应用程序中加载实际图像之前显示占位符图像

使用 Ionic Livereload 导致空白页

Ionic 3 - 添加或构建 iOS 应用程序时出错