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)
);
}
来源:https://blog.csdn.net/zj5291407020/article/details/100906715