diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..7029d4f --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +cursor.md diff --git a/cursor.md b/cursor.md new file mode 100644 index 0000000..209ed5f --- /dev/null +++ b/cursor.md @@ -0,0 +1,32 @@ + +使用方法:修改需求里的内容,将需求和步骤内容作为指令让cursor进行执行。 + + +需求: +1. 更新iOS JPush SDK 到 x.x.x 版本, JPush SDK 包的路径是:xxx +2. 更新Android JPush SDK 到 x.x.x 版本, JPush SDK 包的路径是:xxx +3. 将原生iOS、Android SDK 新增的方法,封装在插件中。 + 原生SDK新增方法一: + iOS: + ``` + ``` + + Android: + ``` + ``` + + 统一封装为 方法名为 "" 的对外方法。 + + +请按照以下步骤完成: + +1. 找到需要升级的iOS JPush SDK,替换src/ios/jpush-ios-x.x.x.xcframework 为需要更新的版本。 +2. 将plugin.xml中关于jpush-ios-x.x.x.xcframework相关的引用,替换为需要更新的版本。 +3. 找到需要升级的Android JPush SDK,替换src/android/jpush-android-x.x.x.jar 为需要更新的版本。 +4. 将plugin.xml中关于jpush-android-x.x.x.jar相关的引用,替换为需要更新的版本。 +5. 封装新增的方法。(如果没有新增的方法就不用执行这一步) +6. 在plugin.xml中更新插件版本号,使用安卓SDK包的版本号。 +7. 在package.json中更新插件版本号,使用安卓SDK包的版本号。 + + + diff --git a/doc/Common_detail_api.md b/doc/Common_detail_api.md index c8baff0..5b7ce80 100644 --- a/doc/Common_detail_api.md +++ b/doc/Common_detail_api.md @@ -586,6 +586,27 @@ document.addEventListener("jpush.receiveMessage", function (event) { } ``` +## 获取通知点击的参数 (Android only) + +### event - jpush.receiveNotifyButtonClick + +#### 代码示例 + +- 在你需要接收通知的的 js 文件中加入: + +```js +document.addEventListener("jpush.receiveNotifyButtonClick", function (event) { + if(device.platform == "Android") { + var msgId = event.msgId; + var platform = event.platform; + var name = event.name; + var actionType = event.actionType; + var action = event.action; + var data = event.data; + } +}, false) +``` + ## 判断系统设置中是否允许当前应用推送 ### API - getUserNotificationSettings 判断系统设置中是否允许当前应用推送。 diff --git a/package.json b/package.json index d53f855..b11a354 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jpush-phonegap-plugin", - "version": "5.8.0", + "version": "5.9.0", "description": "JPush for cordova plugin", "cordova": { "id": "jpush-phonegap-plugin", diff --git a/plugin.xml b/plugin.xml index b90b363..19e3d23 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="5.9.0"> JPush JPush for cordova plugin @@ -48,7 +48,7 @@ - + @@ -244,7 +244,7 @@ android:writePermission="${applicationId}.permission.JPUSH_MESSAGE" /> - + diff --git a/src/android/JPushEventReceiver.java b/src/android/JPushEventReceiver.java index 54786c5..c05e337 100644 --- a/src/android/JPushEventReceiver.java +++ b/src/android/JPushEventReceiver.java @@ -19,6 +19,7 @@ import cn.jpush.android.api.CustomMessage; import cn.jpush.android.api.JPushInterface; import cn.jpush.android.api.JPushMessage; import cn.jpush.android.api.NotificationMessage; +import cn.jpush.android.api.NotificationCustomButton; import cn.jpush.android.helper.Logger; import cn.jpush.android.local.JPushConstants; import cn.jpush.android.service.JPushMessageReceiver; @@ -231,6 +232,23 @@ public class JPushEventReceiver extends JPushMessageReceiver { } } + + @Override + public void onNotifyButtonClick(Context context, NotificationCustomButton notificationCustomButton) { + cn.jiguang.cordova.push.JLogger.d(TAG, "[onNotifyButtonClick], " + notificationCustomButton.toString()); + try { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("msgId", notificationCustomButton.a); + jsonObject.put("platform", notificationCustomButton.b); + jsonObject.put("name", notificationCustomButton.c); + jsonObject.put("actionType", notificationCustomButton.d); + jsonObject.put("action", notificationCustomButton.e); + jsonObject.put("data", notificationCustomButton.f); + cn.jiguang.cordova.push.JPushPlugin.transmitNotifyButtonClick(jsonObject); + } catch (Throwable throwable) { + cn.jiguang.cordova.push.JLogger.d(TAG, "[onNotifyButtonClick] throwable:" + throwable); + } + } interface SuccessCallback{ void onSuccessCallback(JSONObject resultJson) throws JSONException; } diff --git a/src/android/JPushPlugin.java b/src/android/JPushPlugin.java index 3aa8f78..a195c78 100644 --- a/src/android/JPushPlugin.java +++ b/src/android/JPushPlugin.java @@ -197,6 +197,20 @@ public class JPushPlugin extends CordovaPlugin { } }); } + + static void transmitNotifyButtonClick( JSONObject data) { + if (instance == null) { + return; + } + String format = "window.plugins.jPushPlugin.receiveNotifyButtonClickCallback(%s);"; + final String js = String.format(format, data.toString()); + cordovaActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + instance.webView.loadUrl("javascript:" + js); + } + }); + } static void transmitNotificationOpen(JSONObject data) { diff --git a/src/android/libs/jpush-android-5.8.0.jar b/src/android/libs/jpush-android-5.9.0.jar similarity index 59% rename from src/android/libs/jpush-android-5.8.0.jar rename to src/android/libs/jpush-android-5.9.0.jar index 40b21cf..6568682 100644 Binary files a/src/android/libs/jpush-android-5.8.0.jar and b/src/android/libs/jpush-android-5.9.0.jar differ diff --git a/src/ios/Plugins/JPushPlugin.h b/src/ios/Plugins/JPushPlugin.h index 7055d5d..17c68b0 100644 --- a/src/ios/Plugins/JPushPlugin.h +++ b/src/ios/Plugins/JPushPlugin.h @@ -76,10 +76,14 @@ static NSMutableDictionary *_jpushEventCache; // 设置手机号 -(void)setMobileNumber:(CDVInvokedUrlCommand*)command; +// 设置进入后台是否允许长连接 (iOS 5.9.0+) +-(void)setBackgroundEnable:(CDVInvokedUrlCommand*)command; + /* * 以下为js中可监听到的事件 * jpush.openNotification 点击推送消息启动或唤醒app * jpush.receiveMessage 收到自定义消息 + * jpush.receiveNotifyButtonClick 收到通知栏自定义按钮点击事件 * jpush.receiveNotification 前台收到推送 * jpush.backgroundNotification 后台收到推送 */ diff --git a/src/ios/Plugins/JPushPlugin.m b/src/ios/Plugins/JPushPlugin.m index 30984a0..0367135 100644 --- a/src/ios/Plugins/JPushPlugin.m +++ b/src/ios/Plugins/JPushPlugin.m @@ -533,6 +533,12 @@ } +#pragma mark - 设置进入后台是否允许长连接 (iOS 5.9.0+) +-(void)setBackgroundEnable:(CDVInvokedUrlCommand *)command { + NSNumber* isEnable = [command argumentAtIndex:0]; + [JPUSHService setBackgroundEnable:[isEnable boolValue]]; +} + #pragma mark - 内部方法 +(void)setupJPushSDK:(NSDictionary*)userInfo{ diff --git a/src/ios/lib/jpush-ios-5.7.0.xcframework/Info.plist b/src/ios/lib/jpush-ios-5.9.0.xcframework/Info.plist similarity index 100% rename from src/ios/lib/jpush-ios-5.7.0.xcframework/Info.plist rename to src/ios/lib/jpush-ios-5.9.0.xcframework/Info.plist diff --git a/src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64/Headers/JPUSHService.h b/src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64/Headers/JPUSHService.h similarity index 99% rename from src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64/Headers/JPUSHService.h rename to src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64/Headers/JPUSHService.h index 1624d45..5752e8a 100644 --- a/src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64/Headers/JPUSHService.h +++ b/src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64/Headers/JPUSHService.h @@ -9,7 +9,7 @@ * Copyright (c) 2011 ~ 2017 Shenzhen HXHG. All rights reserved. */ -#define JPUSH_VERSION_NUMBER 5.7.0 +#define JPUSH_VERSION_NUMBER 5.9.0 #import @@ -822,6 +822,16 @@ typedef NS_ENUM(NSUInteger, JPAuthorizationStatus) { */ + (void)setPushEnable:(BOOL)isEnable completion:(nullable void (^)(NSInteger iResCode))completion; +/*! + * @abstract 设置进入后台是否允许长连接 + * + * @param isEnable YES:允许,NO:不允许,默认是NO,进入后台会关闭长连接,回到前台会重新接入。 + * + * @discussion 请在初始化函数之前调用 + * + */ ++ (void)setBackgroundEnable:(BOOL)isEnable; + /*! * @abstract 设置用户分群推送功能开关 * diff --git a/src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64/PrivacyInfo.xcprivacy b/src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64/PrivacyInfo.xcprivacy similarity index 100% rename from src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64/PrivacyInfo.xcprivacy rename to src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64/PrivacyInfo.xcprivacy diff --git a/src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64/libJPush.a b/src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64/libJPush.a similarity index 88% rename from src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64/libJPush.a rename to src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64/libJPush.a index 1e6e073..5690e20 100644 Binary files a/src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64/libJPush.a and b/src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64/libJPush.a differ diff --git a/src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64_x86_64-simulator/Headers/JPUSHService.h b/src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64_x86_64-simulator/Headers/JPUSHService.h similarity index 99% rename from src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64_x86_64-simulator/Headers/JPUSHService.h rename to src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64_x86_64-simulator/Headers/JPUSHService.h index 1624d45..5752e8a 100644 --- a/src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64_x86_64-simulator/Headers/JPUSHService.h +++ b/src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64_x86_64-simulator/Headers/JPUSHService.h @@ -9,7 +9,7 @@ * Copyright (c) 2011 ~ 2017 Shenzhen HXHG. All rights reserved. */ -#define JPUSH_VERSION_NUMBER 5.7.0 +#define JPUSH_VERSION_NUMBER 5.9.0 #import @@ -822,6 +822,16 @@ typedef NS_ENUM(NSUInteger, JPAuthorizationStatus) { */ + (void)setPushEnable:(BOOL)isEnable completion:(nullable void (^)(NSInteger iResCode))completion; +/*! + * @abstract 设置进入后台是否允许长连接 + * + * @param isEnable YES:允许,NO:不允许,默认是NO,进入后台会关闭长连接,回到前台会重新接入。 + * + * @discussion 请在初始化函数之前调用 + * + */ ++ (void)setBackgroundEnable:(BOOL)isEnable; + /*! * @abstract 设置用户分群推送功能开关 * diff --git a/src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64_x86_64-simulator/PrivacyInfo.xcprivacy b/src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64_x86_64-simulator/PrivacyInfo.xcprivacy similarity index 100% rename from src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64_x86_64-simulator/PrivacyInfo.xcprivacy rename to src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64_x86_64-simulator/PrivacyInfo.xcprivacy diff --git a/src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64_x86_64-simulator/libJPush.a b/src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64_x86_64-simulator/libJPush.a similarity index 78% rename from src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64_x86_64-simulator/libJPush.a rename to src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64_x86_64-simulator/libJPush.a index d81a0c4..11cfa42 100644 Binary files a/src/ios/lib/jpush-ios-5.7.0.xcframework/ios-arm64_x86_64-simulator/libJPush.a and b/src/ios/lib/jpush-ios-5.9.0.xcframework/ios-arm64_x86_64-simulator/libJPush.a differ diff --git a/www/JPushPlugin.js b/www/JPushPlugin.js index eebb143..f068b45 100644 --- a/www/JPushPlugin.js +++ b/www/JPushPlugin.js @@ -5,6 +5,7 @@ var JPushPlugin = function() {}; JPushPlugin.prototype.receiveMessage = {}; JPushPlugin.prototype.openNotification = {}; JPushPlugin.prototype.receiveNotification = {}; +JPushPlugin.prototype.notifyButtonClick = {}; JPushPlugin.prototype.isPlatformIOS = function() { return ( @@ -390,6 +391,14 @@ JPushPlugin.prototype.receiveInAppMessageShowCallback = function(data) { } }; +JPushPlugin.prototype.receiveNotifyButtonClickCallback = function(data) { + if (device.platform === "Android") { + data = JSON.stringify(data); + this.notifyButtonClick = JSON.parse(data); + cordova.fireDocumentEvent("jpush.receiveNotifyButtonClick", this.notifyButtonClick); + } +}; + JPushPlugin.prototype.openNotificationInAndroidCallback = function(data) { data = JSON.stringify(data); this.openNotification = JSON.parse(data); @@ -523,6 +532,17 @@ JPushPlugin.prototype.setAuth = function(isAuth){ }; +/** + * 设置进入后台是否允许长连接 (iOS 5.9.0+) + * + * @param isEnable boolean 是否允许长连接 + */ +JPushPlugin.prototype.setBackgroundEnable = function(isEnable) { + if (this.isPlatformIOS()) { + this.callNative("setBackgroundEnable", [isEnable], null); + } +}; + if (!window.plugins) { window.plugins = {}; }