react-native整合极光推送

我只是一个虾纸丫 提交于 2019-11-29 20:04:13
title date tags
react-native 0.42 整合极光推送
2019-08-29 07:44:20 -0700
react-native

极光推送官网注册应用

配置jpush-react-native

github地址:https://github.com/jpush/jpush-react-native 同样的,打开终端在项目根目录下输入:

npm install jcore-react-native@1.0.0 --save
npm install jpush-react-native@1.5.0 --save

下载完成后,按1、2、3的顺序修改如下文件:

在1中修改如下:

include ':jpush-react-native'
project(':jpush-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jpush-react-native/android')
include ':jcore-react-native'
project(':jcore-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jcore-react-native/android')

在2中修改如下:

android {
    defaultConfig {
        applicationId "yourApplicationId" //就是在极光注册的包名
        ...
        manifestPlaceholders = [
                JPUSH_APPKEY: "yourAppKey", //在此替换你的APPKey
                APP_CHANNEL: "developer-default"    //应用渠道号
        ]
    }
}
...
dependencies {
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile project(':jpush-react-native')
    compile project(':jcore-react-native')
    compile "com.facebook.react:react-native:+"  // From node_modules
}

在3中修改如下:

 <!--添加通知权限,${ApplicationID}替换成你的applicationID!-->
    <premission 
        android:name="${ApplicationID}.permission.JPUSH_MESSAGE"
        android:protectionLevel="signature"/>

    <application
        ...
        >
        ...
        <!-- Required . Enable it you can get statistics data with channel -->
        <meta-data android:name="JPUSH_CHANNEL" android:value="${APP_CHANNEL}"/>
        <meta-data android:name="JPUSH_APPKEY" android:value="${JPUSH_APPKEY}"/>
    </application>

打开MainApplication.java,修改如下:

@Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
                    new JPushPackage(false,false)
            );
        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!