Ionic 4 FCM推送通知未接收通知

时间:2019-12-16 06:57:02

标签: ionic-framework google-cloud-firestore firebase-cloud-messaging

我在Ionic 4中实现了FCM推送通知。它从api发送消息,但未在设备中接收到消息。当我建立apk时,给出了这个错误,但apk正在成功建立。但是我想也许这就是问题吗?而且我已经导入了google-service.json

它在以前的Firebase应用程序中正常工作,但现在我更改了Firebase应用程序却无法正常工作

> Configure project :app
FCM PLUGIN GRADLE TOOLS VERSION: 3.5.0registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

这是我的app.component.ts代码

this.platform.ready().then(() => {

this.fcm.getToken().then(token => {
  console.log(token);
});
// refresh token
this.fcm.onTokenRefresh().subscribe(token => {
  console.log(token);
});
// receive notification
this.fcm.onNotification().subscribe(data => {
  console.log(data);
  if (data.wasTapped) {
    console.log(JSON.stringify(data));
    //this.vibration.vibrate(500); 
  } else {
    console.log('Received in foreground');
  }
});


  this.statusBar.styleDefault();
  this.splashScreen.hide();

  // this.keyboard.hideFormAccessoryBar(false);
  // Initialize i18n TranslationService based on language set on the environments
  this.translateService.setDefaultLang(language);
  this.translate$ = this.translateService.getTranslation(language).subscribe(translation => {
    this.translation.setTranslation(translation);
  });
});

build.gradle中的缺陷

dependencies {
    implementation fileTree(dir: 'libs', include: '*.jar')
    // SUB-PROJECT DEPENDENCIES START
    implementation(project(path: ":CordovaLib"))
    implementation "com.google.firebase:firebase-core:16.0.9"
    implementation "com.google.firebase:firebase-messaging:18.0.0"
    implementation "com.android.support:support-annotations:27.+"
    // SUB-PROJECT DEPENDENCIES END
}

0 个答案:

没有答案