|
5 | 5 |
|
6 | 6 | [English Document](README_en.md) |
7 | 7 |
|
8 | | -## 注意: |
9 | | - |
10 | | -* jpush-react-native 自 1.4.4 之后, 需要安装 [jcore-react-native](https://github.com/jpush/jcore-react-native) |
11 | | -* 安装完后,需要执行 `react-native link`。如果出错了,无需惊慌,手动配置一下即可,具体可参考这篇[文章](http://bbs.reactnative.cn/topic/3505/%E7%94%A8-jpush-react-native-%E6%8F%92%E4%BB%B6%E5%BF%AB%E9%80%9F%E9%9B%86%E6%88%90%E6%8E%A8%E9%80%81%E5%8A%9F%E8%83%BD-android-%E7%AF%87) |
12 | | - |
13 | 8 | ## 安装 |
14 | 9 |
|
15 | 10 | ``` |
16 | 11 | npm install jpush-react-native jcore-react-native --save |
17 | 12 | ``` |
18 | | -## 配置 |
19 | | - |
20 | | -配置包括两个步骤,自动配置和手动操作。 |
21 | | - |
22 | | -### 1.自动配置部分(以下命令均在你的 React Native Project 目录下运行) |
23 | | - |
24 | | -如果工程不是通过 Cocoapods 来集成 ReactNative 的可以直接使用下面代码来 link 插件。 |
25 | | -``` |
26 | | -react-native link |
27 | | -``` |
28 | | - |
29 | | -根据提示,输入 `appKey` 等即可。 |
30 | | - |
31 | | -自动配置操作会自动插入 Native 代码(iOS 中使用 Appdelegate.m 文件名,如果修改了该文件名需要手动插入[代码](documents/ios_usage.md)),这个部分用户无需关系具体细节。 |
32 | | - |
33 | | - |
34 | | - |
35 | | -##### (如果是原生应用集成 react-native)使用 CocoaPods 安装 |
36 | | - |
37 | | -##### 如果你的 React Native 是通过 Cocoapods 来集成的则使用下面两个步骤来集成,注意: 使用 pod 就不要使用 react-native link 了,不然会有冲突。 |
38 | | - |
39 | | -1. 在 Podfile 中添加如下代码: |
40 | | - |
41 | | -``` |
42 | | -pod 'JPushRN', :path => '../node_modules/jpush-react-native' |
43 | | -``` |
44 | | - |
45 | | -2. 终端执行如下指令: |
46 | | - |
47 | | -``` |
48 | | -pod install |
49 | | -``` |
50 | 13 |
|
51 | | -### 2.手动操作部分(自动配置后,部分操作需要手动修改) |
52 | | - |
53 | | -#### iOS 手动操作部分 (3 个步骤) |
| 14 | +## 配置 |
54 | 15 |
|
55 | | -* 在 iOS 工程中设置 TARGETS-> BUILD Phases -> LinkBinary with Libraries 找到 UserNotifications.framework 把 status 设为 optional |
| 16 | +#### 1. iOS 手动操作部分 (3 个步骤) |
56 | 17 |
|
57 | | -* 在 iOS 工程中如果找不到头文件可能要在 TARGETS-> BUILD SETTINGS -> Search Paths -> Header Search Paths 添加如下路径 |
| 18 | +- 在 iOS 工程中设置 TARGETS-> BUILD Phases -> LinkBinary with Libraries 找到 UserNotifications.framework 把 status 设为 optional |
| 19 | +- 在 iOS 工程中如果找不到头文件可能要在 TARGETS-> BUILD SETTINGS -> Search Paths -> Header Search Paths 添加如下路径 |
58 | 20 |
|
59 | 21 | ``` |
60 | 22 | $(SRCROOT)/../node_modules/jpush-react-native/ios/RCTJPushModule |
61 | 23 | ``` |
62 | 24 |
|
63 | | -* 在 xcode8 之后需要点开推送选项: TARGETS -> Capabilities -> Push Notification 设为 on 状态 |
64 | | - |
65 | | -#### Android 手动操作部分 (3 个步骤) |
66 | | - |
67 | | -* 修改 app 下的 build.gradle 配置: |
68 | | - |
69 | | -> your react native project/android/app/build.gradle |
70 | | -
|
71 | | -``` |
72 | | -android { |
73 | | - defaultConfig { |
74 | | - applicationId "yourApplicationId" |
75 | | - ... |
76 | | - manifestPlaceholders = [ |
77 | | - JPUSH_APPKEY: "yourAppKey", //在此替换你的APPKey |
78 | | - APP_CHANNEL: "developer-default" //应用渠道号 |
79 | | - ] |
80 | | - } |
81 | | -} |
82 | | -... |
83 | | -dependencies { |
84 | | - implementation fileTree(dir: "libs", include: ["*.jar"]) |
85 | | - implementation project(':jpush-react-native') // 添加 jpush 依赖 |
86 | | - implementation project(':jcore-react-native') // 添加 jcore 依赖 |
87 | | - implementation "com.facebook.react:react-native:+" // From node_modules |
88 | | -} |
89 | | -``` |
90 | | - |
91 | | -将此处的 yourApplicationId 替换为你的项目的包名;yourAppKey 替换成你在官网上申请的应用的 AppKey。 |
92 | | - |
93 | | -* [检查添加的配置项](documents/check.md) |
94 | | - |
95 | | -* [加入 JPushPackage,有参数!](documents/android_usage.md) |
| 25 | +- 在 xcode8 之后需要点开推送选项: TARGETS -> Capabilities -> Push Notification 设为 on 状态 |
| 26 | + |
| 27 | +#### 2. Android 手动操作部分 (3 个步骤) |
| 28 | + |
| 29 | +- 修改 app 下的 build.gradle 配置: |
| 30 | + |
| 31 | + > your react native project/android/app/build.gradle |
| 32 | +
|
| 33 | + ```java |
| 34 | + android { |
| 35 | + defaultConfig { |
| 36 | + applicationId "yourApplicationId" |
| 37 | + ... |
| 38 | + manifestPlaceholders = [ |
| 39 | + JPUSH_APPKEY: "yourAppKey", //在此替换你的APPKey |
| 40 | + JPUSH_CHANNEL: "developer-default" //在此替换你的channel |
| 41 | + ] |
| 42 | + } |
| 43 | + } |
| 44 | + ... |
| 45 | + dependencies { |
| 46 | + implementation fileTree(dir: "libs", include: ["*.jar"]) |
| 47 | + implementation project(':jpush-react-native') // 添加 jpush 依赖 |
| 48 | + implementation project(':jcore-react-native') // 添加 jcore 依赖 |
| 49 | + implementation "com.facebook.react:react-native:+" // From node_modules |
| 50 | + } |
| 51 | + ``` |
| 52 | + |
| 53 | +- 修改setting.gradle配置: |
| 54 | + |
| 55 | + ```java |
| 56 | + include ':jpush-react-native' |
| 57 | + project(':jpush-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jpush-react-native/android') |
| 58 | + include ':jcore-react-native' |
| 59 | + project(':jcore-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/jcore-react-native/android') |
| 60 | + ``` |
| 61 | + |
| 62 | + **操作完成后点击AndroidStudio的构建** |
| 63 | + |
| 64 | +- 在Application中添加JPush |
| 65 | + |
| 66 | + ```java |
| 67 | + public class MainApplication extends Application implements ReactApplication { |
| 68 | + |
| 69 | + private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { |
| 70 | + @Override |
| 71 | + public boolean getUseDeveloperSupport() { |
| 72 | + return BuildConfig.DEBUG; |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + protected List<ReactPackage> getPackages() { |
| 77 | + @SuppressWarnings("UnnecessaryLocalVariable") |
| 78 | + List<ReactPackage> packages = new PackageList(this).getPackages(); |
| 79 | + //建议在调试期间将参数都设置为true,便于调试 |
| 80 | + packages.add(new JPushPackage(true,true)); |
| 81 | + return packages; |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + protected String getJSMainModuleName() { |
| 86 | + return "index"; |
| 87 | + } |
| 88 | + }; |
| 89 | + |
| 90 | + @Override |
| 91 | + public void onCreate() { |
| 92 | + super.onCreate(); |
| 93 | + SoLoader.init(this, /* native exopackage */ false); |
| 94 | + //强烈建议在Application初始化时调用原生接口的init方法 |
| 95 | + JPushInterface.init(this); |
| 96 | + } |
| 97 | + } |
| 98 | + ``` |
| 99 | + |
| 100 | + |
96 | 101 |
|
97 | 102 | ### API |
98 | 103 |
|
99 | 104 | **Android v1.6.6 版本后新增 notifyJSDidLoad,请务必在接收事件之前调用此方法。** |
100 | 105 |
|
101 | | -* [API](documents/api_en.md) |
| 106 | +- [API](documents/api_en.md) |
102 | 107 |
|
103 | 108 | ### 关于点击通知跳转到指定界面 |
104 | 109 |
|
105 | | -* Android v1.6.7 新增 API `jumpToPushActivity`,使用参考 [demo](example/App.js#L113) |
| 110 | +- Android v1.6.7 新增 API `jumpToPushActivity`,使用参考 [demo](example/App.js#L113) |
106 | 111 |
|
107 | 112 | ## [常见问题](./documents/common_problems.md) |
108 | 113 |
|
109 | | ---- |
| 114 | +------ |
110 | 115 |
|
111 | 116 | ## 贡献者列表 |
112 | 117 |
|
113 | | -* [bang88](https://github.com/bang88) |
114 | | -* [pampang](https://github.com/pampang) |
115 | | -* [huhuanming](https://github.com/huhuanming) |
116 | | -* [arniu](https://github.com/arniu) |
| 118 | +- [bang88](https://github.com/bang88) |
| 119 | +- [pampang](https://github.com/pampang) |
| 120 | +- [huhuanming](https://github.com/huhuanming) |
| 121 | +- [arniu](https://github.com/arniu) |
| 122 | + |
0 commit comments