Skip to content

Commit 39b7987

Browse files
committed
修正安装文档,使安装过程更简洁
1 parent 2c3bd5a commit 39b7987

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

README.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,33 @@
66
77
2. 添加平台
88

9-
cd Myproj :不进行这一步可能会出现[RangeError:Maximum call stack size exceeded]
9+
cd Myproj :不进入项目会出现[RangeError:Maximum call stack size exceeded]
1010
cordova platform add android
11-
11+
cordova platform add ios
1212

1313
### Android使用PhoneGap/Cordova CLI自动安装
1414

15-
1. 使用 phonegap 或者 cordova cli 添加插件(建议在git客户端下使用,在windows 的cmd界面下 该命令提示git command line tool 不可用):
16-
17-
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git
15+
1. 使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
1816

19-
2. 添加device插件,部分API需要根据平台进行调用,需添加org.apache.cordova.device插件
20-
21-
cordova plugin add org.apache.cordova.device
22-
23-
24-
3. 在cn.jpush.phonegap的JPushPlugin.java文件开始处
17+
git clone https://github.com/jpush/jpush-phonegap-plugin.git
18+
19+
2.`$JPUSH_PLUGIN_DIR/plugin.xml`文件中的AppKey替换为在Portal上注册该应用的的Key,例如(9fed5bcb7b9b87413678c407)
20+
21+
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
2522

26-
import your.package.name.R;
27-
import cn.jpush.android.api.JPushInterface;
23+
3.`$JPUSH_PLUGIN_DIR/src/android/JPushPlugin.java` 文件`import your.package.name.R`替换为在Portal上注册该应用的包名,例如(com.thi.pushtest)
2824

2925

30-
>温馨提示:如果使用eclipse来生成安装包,步骤4和5可省略。
31-
>直接在AndroidManifest.xml文件中修改JPUSH_APPKEY即可
26+
4. cordova cli 添加jpush phonegap插件和依赖的device插件:
3227

33-
4. 修改[your project]/plugins/android.json生成脚本的JPUSH_APPKEY字段
28+
cordova plugin add $JPUSH_PLUGIN_DIR
29+
cordova plugin add org.apache.cordova.device
3430

35-
"xml": "<meta-data android:name=\"JPUSH_APPKEY\" android:value=\"your appkey in JPush Portal\" />",
3631

37-
5. 执行 cordova build android 使修改的`JPUSH_APPKEY`写入AndroidManifest.xml文件
38-
6. 在js中调用函数 `window.plugins.jPushPlugin.init();` 初始化jpush sdk
32+
5. 在js中调用函数,初始化jpush sdk
3933

34+
window.plugins.jPushPlugin.init();
35+
window.plugins.jPushPlugin.setDebugMode(true);
4036

4137

4238
###IOS使用PhoneGap/Cordova CLI自动安装

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
154154
<!-- Required . Enable it you can get statistics data with channel -->
155155
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
156-
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
156+
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
157157
</config-file>
158158
<source-file src="src/android/jpush-sdk-release1.7.2.jar" target-dir="libs"/>
159159
<source-file src="src/android/armeabi/libjpush172.so" target-dir="libs/armeabi"/>

src/android/JPushPlugin.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
import org.json.JSONObject;
2020
import java.util.Map.Entry;
2121

22-
//import com.your.package.name.R;
22+
import your.package.name.R;
2323

2424
import cn.jpush.android.api.BasicPushNotificationBuilder;
2525
import cn.jpush.android.api.CustomPushNotificationBuilder;
2626
import cn.jpush.android.api.JPushInterface;
27+
import cn.jpush.android.data.JPushLocalNotification;
2728
import cn.jpush.android.api.TagAliasCallback;
2829

2930
public class JPushPlugin extends CordovaPlugin {
@@ -62,10 +63,11 @@ public JPushPlugin() {
6263
@Override
6364
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
6465
super.initialize(cordova, webView);
65-
JPushInterface.setDebugMode(true);
66-
JPushInterface.init(cordova.getActivity().getApplicationContext());
66+
//JPushInterface.setDebugMode(true);
67+
//JPushInterface.init(cordova.getActivity().getApplicationContext());
6768
}
6869

70+
6971
private static JSONObject notificationObject(String message,
7072
Map<String, Object> extras) {
7173
JSONObject data = new JSONObject();
@@ -162,16 +164,17 @@ void init(JSONArray data,CallbackContext callbackContext){
162164
}
163165

164166
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
165-
String mode;
167+
boolean mode;
166168
try {
167-
mode = data.getString(0);
168-
if (mode.equals("true")) {
169-
JPushInterface.setDebugMode(true);
170-
} else if (mode.equals("false")) {
171-
JPushInterface.setDebugMode(false);
172-
} else {
173-
callbackContext.error("error mode");
174-
}
169+
mode = data.getBoolean(0);
170+
// if (mode.equals("true")) {
171+
// JPushInterface.setDebugMode(true);
172+
// } else if (mode.equals("false")) {
173+
// JPushInterface.setDebugMode(false);
174+
// } else {
175+
// callbackContext.error("error mode");
176+
// }
177+
JPushInterface.setDebugMode(mode);
175178
callbackContext.success();
176179
} catch (JSONException e) {
177180
}
@@ -209,7 +212,7 @@ void setLatestNotificationNum(JSONArray data,
209212
callbackContext.error("error reading num json");
210213
}
211214
if(num != -1){
212-
JPushInterface.setLatestNotifactionNumber(this.cordova.getActivity().getApplicationContext(), num);
215+
JPushInterface.setLatestNotificationNumber(this.cordova.getActivity().getApplicationContext(), num);
213216
}else{
214217
callbackContext.error("error num");
215218
}

www/JPushPlugin.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,12 @@ JPushPlugin.prototype.resumePush = function(){
198198
this.call_native("resumePush",data,null);
199199
}
200200
}
201-
201+
JPushPlugin.prototype.setDebugMode = function(mode){
202+
if(device.platform == "Android") {
203+
this.call_native("setDebugMode",[mode],null);
204+
}
205+
}
206+
//setDebugMode
202207
JPushPlugin.prototype.clearAllNotification = function(){
203208
if(device.platform == "Android") {
204209
data=[]

0 commit comments

Comments
 (0)