修正安装文档,使安装过程更简洁

This commit is contained in:
zhangqinghe 2015-01-19 16:37:44 +08:00
parent 2c3bd5ab38
commit 39b7987b25
4 changed files with 40 additions and 36 deletions

View File

@ -6,37 +6,33 @@
2. 添加平台
cd Myproj :不进行这一步可能会出现[RangeError:Maximum call stack size exceeded]
cd Myproj :不进入项目会出现[RangeError:Maximum call stack size exceeded]
cordova platform add android
cordova platform add ios
### Android使用PhoneGap/Cordova CLI自动安装
1. 使用 phonegap 或者 cordova cli 添加插件(建议在git客户端下使用在windows 的cmd界面下 该命令提示git command line tool 不可用):
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git
1. 使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
2. 添加device插件部分API需要根据平台进行调用需添加org.apache.cordova.device插件
git clone https://github.com/jpush/jpush-phonegap-plugin.git
2. 将`$JPUSH_PLUGIN_DIR/plugin.xml`文件中的AppKey替换为在Portal上注册该应用的的Key,例如9fed5bcb7b9b87413678c407
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
3. 在`$JPUSH_PLUGIN_DIR/src/android/JPushPlugin.java` 文件`import your.package.name.R`替换为在Portal上注册该应用的包名例如(com.thi.pushtest)
4. cordova cli 添加jpush phonegap插件和依赖的device插件:
cordova plugin add $JPUSH_PLUGIN_DIR
cordova plugin add org.apache.cordova.device
3. 在cn.jpush.phonegap的JPushPlugin.java文件开始处
import your.package.name.R;
import cn.jpush.android.api.JPushInterface;
>温馨提示如果使用eclipse来生成安装包步骤4和5可省略。
>直接在AndroidManifest.xml文件中修改JPUSH_APPKEY即可
4. 修改[your project]/plugins/android.json生成脚本的JPUSH_APPKEY字段
"xml": "<meta-data android:name=\"JPUSH_APPKEY\" android:value=\"your appkey in JPush Portal\" />",
5. 执行 cordova build android 使修改的`JPUSH_APPKEY`写入AndroidManifest.xml文件
6. 在js中调用函数 `window.plugins.jPushPlugin.init();` 初始化jpush sdk
5. 在js中调用函数,初始化jpush sdk
window.plugins.jPushPlugin.init();
window.plugins.jPushPlugin.setDebugMode(true);
###IOS使用PhoneGap/Cordova CLI自动安装

View File

@ -153,7 +153,7 @@
<receiver android:name="cn.jpush.android.service.AlarmReceiver"/>
<!-- Required . Enable it you can get statistics data with channel -->
<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default"/>
<meta-data android:name="JPUSH_APPKEY" android:value="299d0fee887820e7d90a68b2"/>
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
</config-file>
<source-file src="src/android/jpush-sdk-release1.7.2.jar" target-dir="libs"/>
<source-file src="src/android/armeabi/libjpush172.so" target-dir="libs/armeabi"/>

View File

@ -19,11 +19,12 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.util.Map.Entry;
//import com.your.package.name.R;
import your.package.name.R;
import cn.jpush.android.api.BasicPushNotificationBuilder;
import cn.jpush.android.api.CustomPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.data.JPushLocalNotification;
import cn.jpush.android.api.TagAliasCallback;
public class JPushPlugin extends CordovaPlugin {
@ -62,10 +63,11 @@ public class JPushPlugin extends CordovaPlugin {
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
JPushInterface.setDebugMode(true);
JPushInterface.init(cordova.getActivity().getApplicationContext());
//JPushInterface.setDebugMode(true);
//JPushInterface.init(cordova.getActivity().getApplicationContext());
}
private static JSONObject notificationObject(String message,
Map<String, Object> extras) {
JSONObject data = new JSONObject();
@ -162,16 +164,17 @@ public class JPushPlugin extends CordovaPlugin {
}
void setDebugMode(JSONArray data, CallbackContext callbackContext) {
String mode;
boolean mode;
try {
mode = data.getString(0);
if (mode.equals("true")) {
JPushInterface.setDebugMode(true);
} else if (mode.equals("false")) {
JPushInterface.setDebugMode(false);
} else {
callbackContext.error("error mode");
}
mode = data.getBoolean(0);
// if (mode.equals("true")) {
// JPushInterface.setDebugMode(true);
// } else if (mode.equals("false")) {
// JPushInterface.setDebugMode(false);
// } else {
// callbackContext.error("error mode");
// }
JPushInterface.setDebugMode(mode);
callbackContext.success();
} catch (JSONException e) {
}
@ -209,7 +212,7 @@ public class JPushPlugin extends CordovaPlugin {
callbackContext.error("error reading num json");
}
if(num != -1){
JPushInterface.setLatestNotifactionNumber(this.cordova.getActivity().getApplicationContext(), num);
JPushInterface.setLatestNotificationNumber(this.cordova.getActivity().getApplicationContext(), num);
}else{
callbackContext.error("error num");
}

View File

@ -198,7 +198,12 @@ JPushPlugin.prototype.resumePush = function(){
this.call_native("resumePush",data,null);
}
}
JPushPlugin.prototype.setDebugMode = function(mode){
if(device.platform == "Android") {
this.call_native("setDebugMode",[mode],null);
}
}
//setDebugMode
JPushPlugin.prototype.clearAllNotification = function(){
if(device.platform == "Android") {
data=[]