mirror of
https://github.com/jpush/jpush-phonegap-plugin.git
synced 2026-02-19 00:07:08 +08:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cb3e22e14 | ||
|
|
a3ad96f786 | ||
|
|
42d64ca2f0 | ||
|
|
0af2f60dbb | ||
|
|
0da9f0ed26 | ||
|
|
f3bc83d97b | ||
|
|
8b674bb777 | ||
|
|
181ab80dab | ||
|
|
de59d7919b | ||
|
|
1102ad3a57 | ||
|
|
a8e4060b4d | ||
|
|
3b234f3101 | ||
|
|
7c580b4eaf | ||
|
|
af267eda94 | ||
|
|
d93b35611b | ||
|
|
d94ccfb8d8 | ||
|
|
b24b7064ba | ||
|
|
f12e7a35d0 | ||
|
|
37c1d308eb | ||
|
|
138fde1587 | ||
|
|
3196aeff72 | ||
|
|
ca2e52fe54 |
38
README.md
38
README.md
@@ -19,30 +19,32 @@ l## JPush PhoneGap Plugin ##
|
||||
|
||||
###Cordova CLI/Phonegap 安装 Android & iOS
|
||||
|
||||
3. 使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
git clone https://github.com/jpush/jpush-phonegap-plugin.git
|
||||
1). 安装JPush PhoneGap Plugin。 有两种方法。
|
||||
|
||||
方法一: 在线安装
|
||||
|
||||
cordova plugin add https://github.com/jpush/jpush-phonegap-plugin.git --variable API_KEY=your_jpush_appkey
|
||||
|
||||
方法二:下载到本地再安装
|
||||
|
||||
使用git命令将jpush phonegap插件下载的本地,将这个目录标记为`$JPUSH_PLUGIN_DIR`
|
||||
|
||||
|
||||
4. 将`$JPUSH_PLUGIN_DIR/plugin.xml`文件中的AppKey替换为在Portal上注册该应用的的Key,例如(9fed5bcb7b9b87413678c407)
|
||||
|
||||
<meta-data android:name="JPUSH_APPKEY" android:value="your appkey"/>
|
||||
|
||||
4. 打开`$JPUSH_PLUGIN_DIR/src/ios/PushConfig.plist`文件将文件中的`7d431e42dfa6a6d693ac2d04`替换为在Portal上注册该应用的的Key,例如(9fed5bcb7b9b87413678c407)
|
||||
|
||||
|
||||
5. 在`$JPUSH_PLUGIN_DIR/src/android/JPushPlugin.java` 文件`import your.package.name.R`替换为在Portal上注册该应用的包名,例如(com.thi.pushtest)
|
||||
git clone https://github.com/jpush/jpush-phonegap-plugin.git
|
||||
cordova plugin add $JPUSH_PLUGIN_DIR --variable API_KEY=your_jpush_appkey
|
||||
|
||||
|
||||
6. cordova cli 添加jpush phonegap插件和依赖的device插件:
|
||||
|
||||
cordova plugin add $JPUSH_PLUGIN_DIR
|
||||
cordova plugin add org.apache.cordova.device
|
||||
|
||||
7. 在js中调用函数,初始化jpush sdk
|
||||
2). 安装org.apache.cordova.device
|
||||
|
||||
cordova plugin add org.apache.cordova.device
|
||||
|
||||
|
||||
3). 在js中调用函数,初始化jpush sdk
|
||||
|
||||
window.plugins.jPushPlugin.init();
|
||||
//由于phonegap插件采用了Lazy load的特性, 所以这里建议在js文件能执行的最开始就加
|
||||
|
||||
window.plugins.jPushPlugin.init();
|
||||
//由于phonegap插件采用了Lazy load的特性, 所以这里建议在js文件能执行的最开始就加
|
||||
|
||||
### Android 手工安装
|
||||
|
||||
|
||||
@@ -54,13 +54,13 @@
|
||||
}
|
||||
var onReceiveNotification = function(event){
|
||||
try{
|
||||
var alert
|
||||
var alertContent
|
||||
if(device.platform == "Android"){
|
||||
alert = window.plugins.jPushPlugin.receiveNotification.alert;
|
||||
alertContent = window.plugins.jPushPlugin.receiveNotification.alert;
|
||||
}else{
|
||||
alert = event.aps.alert;
|
||||
alertContent = event.aps.alert;
|
||||
}
|
||||
$("#notificationResult").html(alert);
|
||||
$("#notificationResult").html(alertContent);
|
||||
|
||||
}
|
||||
catch(exeption){
|
||||
|
||||
19
plugin.xml
19
plugin.xml
@@ -10,12 +10,14 @@
|
||||
<keywords>JPush,push</keywords>
|
||||
<license>Apache 2.0 License</license>
|
||||
|
||||
<preference name="API_KEY" />
|
||||
|
||||
<engines>
|
||||
<engine name="cordova" version=">=3.0"/>
|
||||
</engines>
|
||||
|
||||
<js-module src="www/JPushPlugin.js" name="JPushPlugin">
|
||||
<clobbers target="window.plugins.jPushPlugin"/>
|
||||
<clobbers target="jPushPlugin"/>
|
||||
</js-module>
|
||||
|
||||
<platform name="ios">
|
||||
@@ -42,11 +44,18 @@
|
||||
<framework src="UIKit.framework" weak="true" />
|
||||
<framework src="Security.framework" weak="true" />
|
||||
<framework src="libz.dylib" weak="true" />
|
||||
|
||||
|
||||
<config-file target="*PushConfig.plist" parent="APP_KEY">
|
||||
<string>$API_KEY</string>
|
||||
</config-file>
|
||||
</platform>
|
||||
|
||||
<!-- android -->
|
||||
<platform name="android">
|
||||
<hook type="after_plugin_add" src="scripts/android-install.js" />
|
||||
<hook type="after_plugin_install" src="scripts/android-install.js" />
|
||||
<hook type="before_plugin_rm" src="scripts/android-install.js" />
|
||||
<hook type="before_plugin_uninstall" src="scripts/android-install.js" />
|
||||
|
||||
<config-file target="res/xml/config.xml" parent="/*">
|
||||
<feature name="JPushPlugin">
|
||||
@@ -152,16 +161,16 @@
|
||||
<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="your appkey"/>
|
||||
<meta-data android:name="JPUSH_APPKEY" android:value="$API_KEY"/>
|
||||
</config-file>
|
||||
<source-file src="src/android/jpush-android-2.0.5.jar" target-dir="libs"/>
|
||||
<source-file src="src/android/armeabi/libjpush205.so" target-dir="libs/armeabi"/>
|
||||
<source-file src="src/android/armeabi-v7a/libjpush205.so" target-dir="libs/armeabi-v7a"/>
|
||||
<source-file src="src/android/arm64-v8a/libjpush205.so" target-dir="libs/arm64-v8a"/>
|
||||
|
||||
<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>
|
||||
<!--<source-file src="src/android/JPushPlugin.java" target-dir="src/cn/jpush/phonegap"/>-->
|
||||
<source-file src="src/android/MyReceiver.java" target-dir="src/cn/jpush/phonegap"/>
|
||||
<source-file src="src/android/test_notification_layout.xml" target-dir="res/layout"/>
|
||||
<source-file src="src/android/jpush_notification_icon.png" target-dir="res/drawable"/>
|
||||
</platform>
|
||||
</plugin>
|
||||
</plugin>
|
||||
|
||||
48
scripts/android-install.js
Normal file
48
scripts/android-install.js
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
module.exports = function (context) {
|
||||
var path = context.requireCordovaModule('path'),
|
||||
fs = context.requireCordovaModule('fs'),
|
||||
shell = context.requireCordovaModule('shelljs'),
|
||||
projectRoot = context.opts.projectRoot,
|
||||
ConfigParser = context.requireCordovaModule('cordova-lib/src/configparser/ConfigParser'),
|
||||
config = new ConfigParser(path.join(context.opts.projectRoot, "config.xml")),
|
||||
packageName = config.android_packageName() || config.packageName();
|
||||
|
||||
console.info("Running android-install.Hook: " + context.hook + ", Package: " + packageName + ", Path: " + projectRoot + ".");
|
||||
|
||||
if (!packageName) {
|
||||
console.error("Package name could not be found!");
|
||||
return ;
|
||||
}
|
||||
|
||||
// android platform available?
|
||||
if (context.opts.cordova.platforms.indexOf("android") === -1) {
|
||||
console.info("Android platform has not been added.");
|
||||
return ;
|
||||
}
|
||||
|
||||
var targetDir = path.join(projectRoot, "platforms", "android", "src", "cn", "jpush", "phonegap");
|
||||
targetFile = path.join(targetDir, "JPushPlugin.java");
|
||||
console.log(targetDir);
|
||||
|
||||
if (['after_plugin_add', 'after_plugin_install', 'after_platform_add'].indexOf(context.hook) === -1) {
|
||||
// remove it?
|
||||
try {
|
||||
fs.unlinkSync(targetFile);
|
||||
} catch (err) {}
|
||||
} else {
|
||||
// create directory
|
||||
shell.mkdir('-p', targetDir);
|
||||
|
||||
// sync the content
|
||||
fs.readFile(path.join(context.opts.plugin.dir, 'src', 'android', 'JPushPlugin.java'), {encoding: 'utf-8'}, function (err, data) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
data = data.replace(/^import __PACKAGE_NAME__.R;/m, 'import ' + packageName + '.R;');
|
||||
fs.writeFileSync(targetFile, data);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -19,13 +19,15 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import your.package.name.R;
|
||||
import __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;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class JPushPlugin extends CordovaPlugin {
|
||||
private final static List<String> methodList =
|
||||
@@ -46,6 +48,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
"setLatestNotificationNum",
|
||||
"setPushTime",
|
||||
"clearAllNotification",
|
||||
"clearNotificationById",
|
||||
"addLocalNotification",
|
||||
"removeLocalNotification",
|
||||
"clearLocalNotifications",
|
||||
@@ -55,7 +58,9 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
|
||||
private ExecutorService threadPool = Executors.newFixedThreadPool(1);
|
||||
private static JPushPlugin instance;
|
||||
private static String TAG = "Client JPushPlugin";
|
||||
|
||||
public static boolean bOpenNotificationAlert = true;
|
||||
public static String notificationAlert;
|
||||
public static Map<String, Object> notificationExtras=new HashMap<String, Object>();
|
||||
public static String openNotificationAlert;
|
||||
@@ -72,12 +77,19 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
|
||||
//JPushPlugin.notificationAlert = alert;
|
||||
//JPushPlugin.notificationExtras = extras;
|
||||
if(JPushPlugin.openNotificationAlert != null){
|
||||
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
|
||||
}
|
||||
if(JPushPlugin.notificationAlert!=null){
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
|
||||
}
|
||||
|
||||
if(JPushPlugin.bOpenNotificationAlert){
|
||||
|
||||
JPushPlugin.bOpenNotificationAlert = false;
|
||||
if(JPushPlugin.openNotificationAlert != null){
|
||||
JPushPlugin.transmitOpen(JPushPlugin.openNotificationAlert, JPushPlugin.openNotificationExtras);
|
||||
}
|
||||
if(JPushPlugin.notificationAlert!=null){
|
||||
JPushPlugin.transmitReceive(JPushPlugin.notificationAlert, JPushPlugin.notificationExtras);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//JPushInterface.init(cordova.getActivity().getApplicationContext());
|
||||
}
|
||||
@@ -225,7 +237,7 @@ public class JPushPlugin extends CordovaPlugin {
|
||||
JSONArray.class, CallbackContext.class);
|
||||
method.invoke(JPushPlugin.this, data, callbackContext);
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.toString());
|
||||
Log.e(TAG,e.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MyReceiver extends BroadcastReceiver {
|
||||
Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
|
||||
launch.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
||||
JPushPlugin.bOpenNotificationAlert = true;
|
||||
JPushPlugin.openNotificationAlert = alert;
|
||||
JPushPlugin.openNotificationExtras = extras;
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>APP_KEY</key>
|
||||
<string>7d431e42dfa6a6d693ac2d04</string>
|
||||
<key>CHANNEL</key>
|
||||
<string>Subscription</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>APP_KEY</key>
|
||||
<string></string>
|
||||
<key>CHANNEL</key>
|
||||
<string>Subscription</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -253,6 +253,13 @@ JPushPlugin.prototype.clearAllNotification = function(){
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.clearNotificationById = function(notificationId){
|
||||
if(device.platform == "Android") {
|
||||
data=[]
|
||||
this.call_native("clearNotificationById",[notificationId],null);
|
||||
}
|
||||
}
|
||||
|
||||
JPushPlugin.prototype.setLatestNotificationNum = function(num){
|
||||
if(device.platform == "Android") {
|
||||
this.call_native("setLatestNotificationNum",[num],null);
|
||||
|
||||
Reference in New Issue
Block a user