首页 > 解决方案 > 无法为 Android/IOS 应用程序 Ionic 检索 Firebase 云的 FCM 令牌

问题描述

我正在构建一个 Ionic Android/IOS 应用程序,其中包括来自 firebase 云消息传递的推送通知。但是,我在检索令牌时遇到问题。

我尝试了几种变体,但它们都会导致错误。

...
import { FCM } from '@ionic-native/fcm/ngx';
import { AngularFireMessaging } from '@angular/fire/messaging';
import { Firebase } from '@ionic-native/firebase/ngx';

@Injectable()
export class FcmNotificationProvider {
  constructor(
    public firebaseNative : Firebase,
    public afs: AngularFirestore,
    public afMessaging : AngularFireMessaging,
    private platform: Platform,
    private fcm: FCM
  ) {}

getToken() {

this.fcm.getToken
      .subscribe(
        (token) => { alert('We got a token', token); },
        (error) => { alert(error); },  
      );
}}

// gives an error
Error: Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function

在我的 android 设备上运行时,我也尝试使用AngularFireMessaging并得到不同的错误。

    this.afMessaging.getToken
      .subscribe(
        (token) => { alert('We got a token', token); },
        (error) => { alert(error); },  
      );

当我在我的设备上安装并运行 apk 时,出现以下错误: "This browser doesnt support the API's required to use the firebase SDK. (messaging/unsupported-browser).

关于我在这里做错了什么的任何想法?

标签: androidfirebaseionic-frameworkfirebase-cloud-messaging

解决方案


推荐阅读