Ionic中的Firebase推送通知 [英] Firebase push notification in Ionic

查看:441
本文介绍了Ionic中的Firebase推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助将我的Ionic应用程序连接到FCM。我需要在实时数据库中的条目发送时发送推送通知。我尝试过以下方法:

I need help connecting my Ionic app to FCM. I need to send push notifications when entries in the Real Time Database are made. I have tried the following:


  1. 离子原生推送

  2. Ionic Native FCM

  3. AngularFire2

  1. Ionic Native Push
  2. Ionic Native FCM
  3. AngularFire2

但是,当我尝试上述所有方法都会给我带来错误要部署到设备或构建应用程序,我收到以下错误:

But, all of the above approaches give me errors when I try to deploy to device or build the app, I get the following error:


任务'执行失败':processDebugGoogleServices'。

Execution failed for task ':processDebugGoogleServices'.

知道怎么办?我很可能没有正确配置Firebase。我在根目录中放置了 google-services.json ,没有问题。

Any idea how to proceed? I'm most probably not configuring Firebase properly. I have placed google-services.json in the root directory, no problems there.

非常感谢任何帮助。

推荐答案

尝试在fcm插件目录下更改此文件

try to change this file under fcm plugin directory

/plugins/cordova-plugin-fcm/src/android/FCMPlugin.gradle

/plugins/cordova-plugin-fcm/src/android/FCMPlugin.gradle

buildscript {
    repositories {
            jcenter()
            mavenLocal()
        }
    dependencies {
        classpath 'com.android.tools.build:gradle:+'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
// apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
ext.postBuildExtras = {
    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}

然后

ionic cordova platform rm android
ionic cordova platform add android

然后更改此文件
/platforms/android/project.properties

then change this file /platforms/android/project.properties

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
# Project target.
target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.facebook.android:facebook-android-sdk:4.+
cordova.system.library.2=com.google.firebase:firebase-core:11.4.2
cordova.system.library.3=com.google.firebase:firebase-messaging:11.4.2
cordova.gradle.include.1=cordova-plugin-fcm/mobile-FCMPlugin.gradle
cordova.system.library.4=com.google.android.gms:play-services-auth:11.4.2
cordova.system.library.5=com.google.android.gms:play-services-identity:11.4.2
cordova.system.library.6=com.android.support:support-v4:24.1.1+
cordova.gradle.include.2=cordova-support-google-services/mobile-build.gradle
cordova.gradle.include.3=twitter-connect-plugin/mobile-twitter.gradle
cordova.system.library.7=com.squareup.okhttp3:okhttp:3+

然后构建

ionic cordova build android

这篇关于Ionic中的Firebase推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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