diff --git a/.npmignore b/.npmignore index 90c978b3..2929c4a5 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,2 @@ example/ +cursor.md diff --git a/JPush.podspec b/JPushRN.podspec similarity index 88% rename from JPush.podspec rename to JPushRN.podspec index 176e1e53..9845091a 100644 --- a/JPush.podspec +++ b/JPushRN.podspec @@ -3,7 +3,7 @@ pjson = JSON.parse(File.read('package.json')) Pod::Spec.new do |s| - s.name = "JPush" + s.name = "JPushRN" s.version = pjson["version"] s.homepage = pjson["homepage"] s.summary = pjson["description"] @@ -18,6 +18,6 @@ Pod::Spec.new do |s| s.frameworks = 'UIKit','CFNetwork','CoreFoundation','CoreTelephony','SystemConfiguration','CoreGraphics','Foundation','Security' s.weak_frameworks = 'UserNotifications' s.libraries = 'z','resolv' - s.vendored_libraries = "ios/RCTJPushModule/*.a" + s.vendored_frameworks = "ios/RCTJPushModule/*.xcframework" s.dependency 'React' end \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index 244f432e..546af6d2 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,10 +5,13 @@ def safeExtGet(prop, fallback) { } android { - compileSdkVersion safeExtGet('compileSdkVersion', 27) + compileSdkVersion safeExtGet('compileSdkVersion', 34) + + namespace 'cn.jiguang.plugins.push' + defaultConfig { - minSdkVersion safeExtGet('minSdkVersion', 16) - targetSdkVersion safeExtGet('targetSdkVersion', 27) + minSdkVersion safeExtGet('minSdkVersion', 23) + targetSdkVersion safeExtGet('targetSdkVersion', 34) versionCode 1 versionName "1.0" diff --git a/android/libs/jpush-android-4.8.0.jar b/android/libs/jpush-android-4.8.0.jar deleted file mode 100644 index 83f7e5b7..00000000 Binary files a/android/libs/jpush-android-4.8.0.jar and /dev/null differ diff --git a/android/libs/jpush-android-5.9.0.jar b/android/libs/jpush-android-5.9.0.jar new file mode 100644 index 00000000..2d928fe2 Binary files /dev/null and b/android/libs/jpush-android-5.9.0.jar differ diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 9c2c3d08..6d14b741 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,38 +1,47 @@ + > - - + + + + + + + + + + + + - + --> + android:exported="true" + android:theme="@style/MyDialogStyle" > + + + + + + @@ -63,7 +72,7 @@ android:enabled="true" android:exported="false"> - + @@ -83,7 +92,7 @@ @@ -95,13 +104,18 @@ android:enabled="true" android:exported="true" android:theme="@android:style/Theme.Translucent.NoTitleBar" - android:taskAffinity="jpush.custom"> + android:taskAffinity=""> - + diff --git a/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java b/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java index ac14ea51..034c1d75 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java +++ b/android/src/main/java/cn/jiguang/plugins/push/JPushModule.java @@ -1,6 +1,9 @@ package cn.jiguang.plugins.push; - +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.net.Uri; +import android.os.Build; import android.app.Activity; import android.app.Application; import android.os.Bundle; @@ -14,12 +17,15 @@ import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.bridge.ReadableNativeMap; import com.facebook.react.bridge.WritableMap; import org.json.JSONObject; +import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import java.lang.*; import cn.jiguang.plugins.push.common.JConstants; import cn.jiguang.plugins.push.common.JLogger; @@ -27,6 +33,7 @@ import cn.jiguang.plugins.push.receiver.JPushBroadcastReceiver; import cn.jpush.android.api.BasicPushNotificationBuilder; import cn.jpush.android.api.JPushInterface; +import cn.jpush.android.data.JPushCollectControl; import cn.jpush.android.data.JPushLocalNotification; public class JPushModule extends ReactContextBaseJavaModule { @@ -59,6 +66,7 @@ public void init() { JPushHelper.sendEvent(JConstants.NOTIFICATION_EVENT, writableMap); JPushBroadcastReceiver.NOTIFICATION_BUNDLE = null; } + JPushInterface.setNotificationCallBackEnable(reactContext,true); } @ReactMethod @@ -95,6 +103,92 @@ public void setChannel(ReadableMap readableMap) { } } @ReactMethod + public void setChannelAndSound(ReadableMap readableMap) { + if (readableMap == null) { + JLogger.w(JConstants.PARAMS_NULL); + return; + } + String channel = readableMap.getString(JConstants.CHANNEL); + String sound = readableMap.getString(JConstants.SOUND); + String channelId = readableMap.getString(JConstants.CHANNELID); + try { + NotificationManager manager= (NotificationManager) reactContext.getSystemService("notification"); + if(Build.VERSION.SDK_INT<26){ + return; + } + if(TextUtils.isEmpty(channel)||TextUtils.isEmpty(channelId)){ + return; + } + NotificationChannel channel1=new NotificationChannel(channelId,channel, NotificationManager.IMPORTANCE_HIGH); + if(!TextUtils.isEmpty(sound)){ + channel1.setSound(Uri.parse("android.resource://"+reactContext.getPackageName()+"/raw/"+sound),null); + } + manager.createNotificationChannel(channel1); + JPushInterface.setChannel(reactContext,channel); + }catch (Throwable throwable){ + } + } + @ReactMethod + public void setLinkMergeEnable(boolean enable) { + JPushInterface.setLinkMergeEnable(reactContext, enable); + } + + @ReactMethod + public void setSmartPushEnable(boolean enable) { + JPushInterface.setSmartPushEnable(reactContext, enable); + } + + @ReactMethod + public void setDataInsightsEnable(boolean enable) { + JPushInterface.setDataInsightsEnable(reactContext, enable); + } + + @ReactMethod + public void setGeofenceEnable(boolean enable) { + JPushInterface.setGeofenceEnable(reactContext, enable); + } + + @ReactMethod + public void setCollectControl(ReadableMap readableMap) { + if (readableMap == null) { + JLogger.w(JConstants.PARAMS_NULL); + return; + } + boolean hadValue = false; + JPushCollectControl.Builder builder = new JPushCollectControl.Builder(); + if (readableMap.hasKey(JConstants.IMEI)) { + hadValue = true; + builder.imei(readableMap.getBoolean(JConstants.IMEI)); + } + if (readableMap.hasKey(JConstants.IMSI)) { + hadValue = true; + builder.imsi(readableMap.getBoolean(JConstants.IMSI)); + } + if (readableMap.hasKey(JConstants.MAC)) { + hadValue = true; + builder.mac(readableMap.getBoolean(JConstants.MAC)); + } + if (readableMap.hasKey(JConstants.WIFI)) { + hadValue = true; + builder.wifi(readableMap.getBoolean(JConstants.WIFI)); + } + if (readableMap.hasKey(JConstants.BSSID)) { + hadValue = true; + builder.bssid(readableMap.getBoolean(JConstants.BSSID)); + } + if (readableMap.hasKey(JConstants.SSID)) { + hadValue = true; + builder.ssid(readableMap.getBoolean(JConstants.SSID)); + } + if (readableMap.hasKey(JConstants.CELL)) { + hadValue = true; + builder.cell(readableMap.getBoolean(JConstants.CELL)); + } + if (hadValue) { + JPushInterface.setCollectControl(reactContext, builder.build()); + } + } + @ReactMethod public void setBadgeNumber(ReadableMap readableMap) { if (readableMap == null) { JLogger.w(JConstants.PARAMS_NULL); @@ -213,7 +307,48 @@ public void filterValidTags(ReadableMap readableMap, Callback callback) { JLogger.w("there are no " + JConstants.TAGS); } } + @ReactMethod + public void setProperties(ReadableMap readableMap) { + if (readableMap == null) { + JLogger.w(JConstants.PARAMS_NULL); + return; + } + if (readableMap.hasKey(JConstants.PROPERTIES)) { + int sequence = readableMap.getInt(JConstants.SEQUENCE); + ReadableMap readMap = readableMap.getMap(JConstants.PROPERTIES); + ReadableNativeMap map= (ReadableNativeMap) readMap; + HashMap properties=map.toHashMap(); + JPushInterface.setProperties(reactContext,sequence,properties); + } else { + JLogger.w("there are no " + JConstants.PROPERTIES); + } + } + @ReactMethod + public void deleteProperties(ReadableMap readableMap) { + if (readableMap == null) { + JLogger.w(JConstants.PARAMS_NULL); + return; + } + if (readableMap.hasKey(JConstants.PROPERTIES)) { + int sequence = readableMap.getInt(JConstants.SEQUENCE); + ReadableMap readMap = readableMap.getMap(JConstants.PROPERTIES); + ReadableNativeMap map= (ReadableNativeMap) readMap; + HashMap properties=map.toHashMap(); + JPushInterface.deleteProperties(reactContext,sequence,properties); + } else { + JLogger.w("there are no " + JConstants.PROPERTIES); + } + } + @ReactMethod + public void cleanProperties(ReadableMap readableMap) { + if (readableMap == null) { + JLogger.w(JConstants.PARAMS_NULL); + return; + } + int sequence = readableMap.getInt(JConstants.SEQUENCE); + JPushInterface.cleanProperties(reactContext,sequence); + } @ReactMethod public void setTags(ReadableMap readableMap) { if (readableMap == null) { @@ -390,15 +525,61 @@ public void addLocalNotification(ReadableMap readableMap) { int id = Integer.valueOf(notificationID); String notificationTitle = readableMap.hasKey(JConstants.TITLE) ? readableMap.getString(JConstants.TITLE) : reactContext.getPackageName(); String notificationContent = readableMap.hasKey(JConstants.CONTENT) ? readableMap.getString(JConstants.CONTENT) : reactContext.getPackageName(); + String broadcastTime = readableMap.hasKey(JConstants.BROADCAST_TIME) ? readableMap.getString(JConstants.BROADCAST_TIME) : "0"; JPushLocalNotification notification = new JPushLocalNotification(); notification.setNotificationId(id); notification.setTitle(notificationTitle); notification.setContent(notificationContent); + try { + notification.setBroadcastTime(Long.parseLong(broadcastTime)); + }catch (Throwable throwable){ + } if (readableMap.hasKey(JConstants.EXTRAS)) { ReadableMap notificationExtra = readableMap.getMap(JConstants.EXTRAS); JSONObject notificationExtraJson = new JSONObject(notificationExtra.toHashMap()); notification.setExtras(notificationExtraJson.toString()); } + + // 设置BuilderId + if (readableMap.hasKey(JConstants.BUILDER_NAME)) { + try { + String layoutFileName = readableMap.getString(JConstants.BUILDER_NAME); + if (!TextUtils.isEmpty(layoutFileName)) { + // 通过布局文件名获取资源ID + int builderId = reactContext.getResources().getIdentifier( + layoutFileName, + "layout", + reactContext.getPackageName() + ); + if (builderId != 0) { + notification.setBuilderId(builderId); + } else { + JLogger.w("Layout file not found: " + layoutFileName); + } + } + } catch (Exception e) { + JLogger.w("Failed to set BuilderId: " + e.getMessage()); + } + } + + // 设置Category + if (readableMap.hasKey(JConstants.CATEGORY)) { + String category = readableMap.getString(JConstants.CATEGORY); + if (!TextUtils.isEmpty(category)) { + notification.setCategory(category); + } + } + + // 设置Priority + if (readableMap.hasKey(JConstants.PRIORITY)) { + try { + int priority = readableMap.getInt(JConstants.PRIORITY); + notification.setPriority(priority); + } catch (Exception e) { + JLogger.w("Priority must be a number"); + } + } + JPushInterface.addLocalNotification(reactContext, notification); } diff --git a/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java b/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java index 47d59898..776a3ae7 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java +++ b/android/src/main/java/cn/jiguang/plugins/push/common/JConstants.java @@ -8,6 +8,8 @@ public class JConstants { public static final String CODE = "code"; public static final String CHANNEL = "channel"; + public static final String CHANNELID = "channelId"; + public static final String SOUND = "sound"; public static final String SEQUENCE = "sequence"; public static final String CONNECT_ENABLE = "connectEnable"; //电话号码 @@ -24,8 +26,12 @@ public class JConstants { //消息 public static final String MESSAGE_ID = "messageID"; public static final String TITLE = "title"; + public static final String BROADCAST_TIME = "broadcastTime"; public static final String CONTENT = "content"; public static final String EXTRAS = "extras"; + public static final String INAPPCLICKACTION = "inAppClickAction"; + public static final String INAPPEXTRAS = "inAppExtras"; + public static final String INAPPSHOWTARGET = "inAppShowTarget"; //消息事件 public static final String NOTIFICATION_ARRIVED = "notificationArrived"; public static final String NOTIFICATION_OPENED = "notificationOpened"; @@ -55,10 +61,28 @@ public class JConstants { //event public static final String CONNECT_EVENT = "ConnectEvent"; public static final String NOTIFICATION_EVENT = "NotificationEvent"; + public static final String INAPP_MESSAGE_EVENT = "InappMessageEvent"; public static final String CUSTOM_MESSAGE_EVENT = "CustomMessageEvent"; public static final String LOCAL_NOTIFICATION_EVENT = "LocalNotificationEvent"; public static final String TAG_ALIAS_EVENT = "TagAliasEvent"; public static final String MOBILE_NUMBER_EVENT = "MobileNumberEvent"; + public static final String NOTIFY_BUTTON_CLICK_EVENT = "NotifyButtonClickEvent"; public static final String COMMAND_EVENT = "CommandEvent"; public static final String BADGE_NUMBER = "badge"; + public static final String PROPERTIES = "pros"; + public static final String IN_APP_MESSAGE_CLICK = "inappClick"; + public static final String IN_APP_MESSAGE_SHOW = "inappShow"; + + public static final String IMEI = "imei"; + public static final String IMSI = "imsi"; + public static final String MAC = "mac"; + public static final String WIFI = "wifi"; + public static final String BSSID = "bssid"; + public static final String SSID = "ssid"; + public static final String CELL = "cell"; + + // 本地通知相关常量 + public static final String BUILDER_NAME = "builderName"; + public static final String CATEGORY = "category"; + public static final String PRIORITY = "priority"; } diff --git a/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java b/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java index 4836701a..d7352aee 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java +++ b/android/src/main/java/cn/jiguang/plugins/push/helper/JPushHelper.java @@ -21,6 +21,7 @@ import cn.jpush.android.api.CustomMessage; import cn.jpush.android.api.JPushMessage; import cn.jpush.android.api.NotificationMessage; +import cn.jpush.android.api.NotificationCustomButton; public class JPushHelper { @@ -41,6 +42,17 @@ public static WritableMap convertNotificationToMap(String eventType, Notificatio convertExtras(message.notificationExtras, writableMap); return writableMap; } + public static WritableMap convertInAppMessageToMap(String eventType, NotificationMessage message) { + WritableMap writableMap = Arguments.createMap(); + writableMap.putString(JConstants.INAPP_MESSAGE_EVENT, eventType); + writableMap.putString(JConstants.MESSAGE_ID, message.msgId); + writableMap.putString(JConstants.TITLE, message.inAppMsgTitle); + writableMap.putString(JConstants.CONTENT, message.inAppMsgContentBody); + writableMap.putString(JConstants.INAPPCLICKACTION, message.inAppClickAction); + writableMap.putString(JConstants.INAPPEXTRAS, message.inAppExtras); + writableMap.putString(JConstants.INAPPSHOWTARGET, message.inAppShowTarget); + return writableMap; + } public static WritableMap convertNotificationBundleToMap(String eventType, Bundle bundle) { WritableMap writableMap = Arguments.createMap(); @@ -61,6 +73,22 @@ public static WritableMap convertCustomMessage(CustomMessage customMessage) { return writableMap; } + public static WritableMap convertNotificationCustomButtonToMap(NotificationCustomButton notificationCustomButton) { + WritableMap writableMap = Arguments.createMap(); + try { + writableMap.putString("msgId", notificationCustomButton.a); + writableMap.putInt("platform", notificationCustomButton.b); + writableMap.putString("name", notificationCustomButton.c); + writableMap.putInt("actionType", notificationCustomButton.d); + writableMap.putString("action", notificationCustomButton.e); + writableMap.putString("data", notificationCustomButton.f); + return writableMap; + } catch (Throwable throwable) { + JLogger.w("convertNotificationCustomButtonToMap error:" + throwable.getMessage()); + return writableMap; + } + } + public static WritableMap convertJPushMessageToMap(int type, JPushMessage message) { WritableMap writableMap = Arguments.createMap(); diff --git a/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java b/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java index 34ba7343..e27f4c52 100644 --- a/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java +++ b/android/src/main/java/cn/jiguang/plugins/push/receiver/JPushModuleReceiver.java @@ -14,6 +14,7 @@ import cn.jpush.android.api.JPushMessage; import cn.jpush.android.api.NotificationMessage; import cn.jpush.android.service.JPushMessageReceiver; +import cn.jpush.android.api.NotificationCustomButton; public class JPushModuleReceiver extends JPushMessageReceiver { @@ -34,7 +35,12 @@ public void onNotifyMessageArrived(Context context, NotificationMessage notifica JPushHelper.sendEvent(JConstants.LOCAL_NOTIFICATION_EVENT, writableMap); } } - + @Override + public void onPropertyOperatorResult(Context context, JPushMessage jPushMessage) { + JLogger.d("onPropertyOperatorResult:" + jPushMessage.toString()); + WritableMap writableMap = JPushHelper.convertJPushMessageToMap(1, jPushMessage); + JPushHelper.sendEvent(JConstants.TAG_ALIAS_EVENT, writableMap); + } @Override public void onNotifyMessageOpened(Context context, NotificationMessage notificationMessage) { JLogger.d("onNotifyMessageOpened:" + notificationMessage.toString()); @@ -46,6 +52,28 @@ public void onNotifyMessageOpened(Context context, NotificationMessage notificat super.onNotifyMessageOpened(context, notificationMessage); } } + @Override + public void onInAppMessageShow(Context context, NotificationMessage notificationMessage) { + JLogger.d("onInAppMessageShow:" + notificationMessage.toString()); + if (JPushModule.reactContext != null) { + if (!JPushModule.isAppForeground) JPushHelper.launchApp(context); + WritableMap writableMap = JPushHelper.convertInAppMessageToMap(JConstants.IN_APP_MESSAGE_SHOW, notificationMessage); + JPushHelper.sendEvent(JConstants.INAPP_MESSAGE_EVENT, writableMap); + } else { + super.onInAppMessageShow(context, notificationMessage); + } + } + @Override + public void onInAppMessageClick(Context context, NotificationMessage notificationMessage) { + JLogger.d("onInAppMessageClick:" + notificationMessage.toString()); + if (JPushModule.reactContext != null) { + if (!JPushModule.isAppForeground) JPushHelper.launchApp(context); + WritableMap writableMap = JPushHelper.convertInAppMessageToMap(JConstants.IN_APP_MESSAGE_CLICK, notificationMessage); + JPushHelper.sendEvent(JConstants.INAPP_MESSAGE_EVENT, writableMap); + } else { + super.onInAppMessageClick(context, notificationMessage); + } + } @Override public void onNotifyMessageDismiss(Context context, NotificationMessage notificationMessage) { @@ -54,6 +82,13 @@ public void onNotifyMessageDismiss(Context context, NotificationMessage notifica JPushHelper.sendEvent(JConstants.NOTIFICATION_EVENT, writableMap); } + @Override + public void onNotifyButtonClick(Context context, NotificationCustomButton notificationCustomButton) { + JLogger.d("onNotifyButtonClick:" + notificationCustomButton.toString()); + WritableMap writableMap = JPushHelper.convertNotificationCustomButtonToMap(notificationCustomButton); + JPushHelper.sendEvent(JConstants.NOTIFY_BUTTON_CLICK_EVENT, writableMap); + } + @Override public void onRegister(Context context, String registrationId) { JLogger.d("onRegister:" + registrationId); diff --git a/android/src/main/res/drawable/jpush_btn_blue_bg.xml b/android/src/main/res/drawable/jpush_btn_blue_bg.xml new file mode 100644 index 00000000..027cebfd --- /dev/null +++ b/android/src/main/res/drawable/jpush_btn_blue_bg.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/android/src/main/res/drawable/jpush_btn_grey_bg.xml b/android/src/main/res/drawable/jpush_btn_grey_bg.xml new file mode 100644 index 00000000..d60ac612 --- /dev/null +++ b/android/src/main/res/drawable/jpush_btn_grey_bg.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/src/main/res/drawable/jpush_cancel_btn_bg.xml b/android/src/main/res/drawable/jpush_cancel_btn_bg.xml new file mode 100644 index 00000000..814e7609 --- /dev/null +++ b/android/src/main/res/drawable/jpush_cancel_btn_bg.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/android/src/main/res/drawable/jpush_close.xml b/android/src/main/res/drawable/jpush_close.xml new file mode 100644 index 00000000..697c1416 --- /dev/null +++ b/android/src/main/res/drawable/jpush_close.xml @@ -0,0 +1,19 @@ + + + + diff --git a/android/src/main/res/drawable/jpush_contain_bg.xml b/android/src/main/res/drawable/jpush_contain_bg.xml new file mode 100644 index 00000000..30d811fb --- /dev/null +++ b/android/src/main/res/drawable/jpush_contain_bg.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/android/src/main/res/drawable/jpush_interstitial_bg.xml b/android/src/main/res/drawable/jpush_interstitial_bg.xml new file mode 100644 index 00000000..769b36dc --- /dev/null +++ b/android/src/main/res/drawable/jpush_interstitial_bg.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/android/src/main/res/layout/jpush_banner.xml b/android/src/main/res/layout/jpush_banner.xml new file mode 100644 index 00000000..675c1bce --- /dev/null +++ b/android/src/main/res/layout/jpush_banner.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/android/src/main/res/layout/jpush_full.xml b/android/src/main/res/layout/jpush_full.xml new file mode 100644 index 00000000..8736f286 --- /dev/null +++ b/android/src/main/res/layout/jpush_full.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + diff --git a/android/src/main/res/layout/jpush_interstitial.xml b/android/src/main/res/layout/jpush_interstitial.xml new file mode 100644 index 00000000..b0bdcc92 --- /dev/null +++ b/android/src/main/res/layout/jpush_interstitial.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cursor.md b/cursor.md new file mode 100644 index 00000000..2f2a0a63 --- /dev/null +++ b/cursor.md @@ -0,0 +1,41 @@ + +使用方法:修改需求里的内容,将需求和步骤内容作为指令让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,替换ios/RCTJPushModule/jpush-ios-x.x.x.xcframework 为需要更新的版本。 +2. 将/ios/RCTJPushModule.xcodeproj/project.pbxproj中关于jpush-ios-x.x.x.xcframework中引用路径的代码,替换为需要更新的版本。 +3. 找到需要升级的Android JPush SDK,替换android/libs/jpush-android-x.x.x.jar 为需要更新的版本。 +4. 在插件中封装需求中需要封装的SDK方法,并在插件示例demo中提供示例调用代码,注意rn插件新增方法还需要再index.js和index.d.ts文件中声明哦。(如果没有需求中没有需要新增的方法,则跳过该步骤) +5. 在package.json中更新插件版本号,在现有版本号上 + 0.0.1 +6. 在example/package.json 中 修改示例 插件的集成版本号。 改为最新的插件版本号。涉及到更改的代码 + + ``` + "dependencies": { + ... + "jpush-react-native": "^x.x.x", + ... + + ``` + + + diff --git a/example/.buckconfig b/example/.buckconfig deleted file mode 100644 index 934256cb..00000000 --- a/example/.buckconfig +++ /dev/null @@ -1,6 +0,0 @@ - -[android] - target = Google Inc.:Google APIs:23 - -[maven_repositories] - central = https://repo1.maven.org/maven2 diff --git a/example/.bundle/config b/example/.bundle/config new file mode 100644 index 00000000..848943bb --- /dev/null +++ b/example/.bundle/config @@ -0,0 +1,2 @@ +BUNDLE_PATH: "vendor/bundle" +BUNDLE_FORCE_RUBY_PLATFORM: 1 diff --git a/example/.eslintrc.js b/example/.eslintrc.js index 40c6dcd0..187894b6 100644 --- a/example/.eslintrc.js +++ b/example/.eslintrc.js @@ -1,4 +1,4 @@ module.exports = { root: true, - extends: '@react-native-community', + extends: '@react-native', }; diff --git a/example/.flowconfig b/example/.flowconfig deleted file mode 100644 index 1319ea12..00000000 --- a/example/.flowconfig +++ /dev/null @@ -1,99 +0,0 @@ -[ignore] -; We fork some components by platform -.*/*[.]android.js - -; Ignore "BUCK" generated dirs -/\.buckd/ - -; Ignore unexpected extra "@providesModule" -.*/node_modules/.*/node_modules/fbjs/.* - -; Ignore duplicate module providers -; For RN Apps installed via npm, "Libraries" folder is inside -; "node_modules/react-native" but in the source repo it is in the root -node_modules/react-native/Libraries/react-native/React.js - -; Ignore polyfills -node_modules/react-native/Libraries/polyfills/.* - -; These should not be required directly -; require from fbjs/lib instead: require('fbjs/lib/warning') -node_modules/warning/.* - -; Flow doesn't support platforms -.*/Libraries/Utilities/HMRLoadingView.js - -[untyped] -.*/node_modules/@react-native-community/cli/.*/.* - -[include] - -[libs] -node_modules/react-native/Libraries/react-native/react-native-interface.js -node_modules/react-native/flow/ - -[options] -emoji=true - -esproposal.optional_chaining=enable -esproposal.nullish_coalescing=enable - -module.file_ext=.js -module.file_ext=.json -module.file_ext=.ios.js - -module.system=haste -module.system.haste.use_name_reducers=true -# get basename -module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1' -# strip .js or .js.flow suffix -module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1' -# strip .ios suffix -module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1' -module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1' -module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1' -module.system.haste.paths.blacklist=.*/__tests__/.* -module.system.haste.paths.blacklist=.*/__mocks__/.* -module.system.haste.paths.whitelist=/node_modules/react-native/Libraries/.* -module.system.haste.paths.whitelist=/node_modules/react-native/RNTester/.* -module.system.haste.paths.whitelist=/node_modules/react-native/IntegrationTests/.* -module.system.haste.paths.blacklist=/node_modules/react-native/Libraries/react-native/react-native-implementation.js -module.system.haste.paths.blacklist=/node_modules/react-native/Libraries/Animated/src/polyfills/.* - -munge_underscores=true - -module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' - -suppress_type=$FlowIssue -suppress_type=$FlowFixMe -suppress_type=$FlowFixMeProps -suppress_type=$FlowFixMeState - -suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\) -suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+ -suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError - -[lints] -sketchy-null-number=warn -sketchy-null-mixed=warn -sketchy-number=warn -untyped-type-import=warn -nonstrict-import=warn -deprecated-type=warn -unsafe-getters-setters=warn -inexact-spread=warn -unnecessary-invariant=warn -signature-verification-failure=warn -deprecated-utility=error - -[strict] -deprecated-type -nonstrict-import -sketchy-null -unclear-type -unsafe-getters-setters -untyped-import -untyped-type-import - -[version] -^0.98.0 diff --git a/example/.gitattributes b/example/.gitattributes deleted file mode 100644 index d42ff183..00000000 --- a/example/.gitattributes +++ /dev/null @@ -1 +0,0 @@ -*.pbxproj -text diff --git a/example/.gitignore b/example/.gitignore index 828cc884..d5ae4566 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -20,7 +20,7 @@ DerivedData *.hmap *.ipa *.xcuserstate -project.xcworkspace +**/.xcode.env.local # Android/IntelliJ # @@ -29,6 +29,10 @@ build/ .gradle local.properties *.iml +*.hprof +.cxx/ +*.keystore +!debug.keystore # node.js # @@ -36,11 +40,6 @@ node_modules/ npm-debug.log yarn-error.log -# BUCK -buck-out/ -\.buckd/ -*.keystore - # fastlane # # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the @@ -48,12 +47,28 @@ buck-out/ # For more information about the recommended setup visit: # https://docs.fastlane.tools/best-practices/source-control/ -*/fastlane/report.xml -*/fastlane/Preview.html -*/fastlane/screenshots +**/fastlane/report.xml +**/fastlane/Preview.html +**/fastlane/screenshots +**/fastlane/test_output # Bundle artifact *.jsbundle -# CocoaPods -/ios/Pods/ +# Ruby / CocoaPods +**/Pods/ +/vendor/bundle/ + +# Temporary files created by Metro to check the health of the file watcher +.metro-health-check* + +# testing +/coverage + +# Yarn +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/sdks +!.yarn/versions diff --git a/example/.prettierrc.js b/example/.prettierrc.js index 5c4de1a4..2b540746 100644 --- a/example/.prettierrc.js +++ b/example/.prettierrc.js @@ -1,6 +1,7 @@ module.exports = { + arrowParens: 'avoid', + bracketSameLine: true, bracketSpacing: false, - jsxBracketSameLine: true, singleQuote: true, trailingComma: 'all', }; diff --git a/example/.watchmanconfig b/example/.watchmanconfig index 9e26dfee..0967ef42 100644 --- a/example/.watchmanconfig +++ b/example/.watchmanconfig @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/example/App.js b/example/App.js index 55187fb4..61449fd3 100644 --- a/example/App.js +++ b/example/App.js @@ -3,150 +3,169 @@ import {StyleSheet, Text, View, TouchableHighlight} from 'react-native'; import JPush from 'jpush-react-native'; const styles = StyleSheet.create({ - container: { - flex: 1, - justifyContent: 'center', - alignItems: 'center', - backgroundColor: '#F5FCFF', - }, - setBtnStyle: { - width: 320, - justifyContent: 'center', - alignItems: 'center', - marginTop: 10, - borderWidth: 1, - borderColor: '#3e83d7', - borderRadius: 8, - backgroundColor: '#3e83d7', - padding: 10 - }, - textStyle: { - textAlign: 'center', - fontSize: 25, - color: '#ffffff' - } + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: '#F5FCFF', + }, + setBtnStyle: { + width: 320, + justifyContent: 'center', + alignItems: 'center', + marginTop: 10, + borderWidth: 1, + borderColor: '#3e83d7', + borderRadius: 8, + backgroundColor: '#3e83d7', + padding: 10 + }, + textStyle: { + textAlign: 'center', + fontSize: 25, + color: '#ffffff' + } }); class Button extends React.Component { - render() { - return - - - {this.props.title} - - - - } + render() { + return + + + {this.props.title} + + + + } } export default class App extends React.Component { - constructor(props) { - super(props); - } - - componentDidMount() { - JPush.init({"appKey":"129c21dc4cb5e6f6de194003","channel":"dev","production":1}); - //连接状态 - this.connectListener = result => { - console.log("connectListener:" + JSON.stringify(result)) - }; - JPush.addConnectEventListener(this.connectListener); - //通知回调 - this.notificationListener = result => { - console.log("notificationListener:" + JSON.stringify(result)) - }; - JPush.addNotificationListener(this.notificationListener); - //本地通知回调 - this.localNotificationListener = result => { - console.log("localNotificationListener:" + JSON.stringify(result)) - }; - JPush.addLocalNotificationListener(this.localNotificationListener); - //自定义消息回调 - // this.customMessageListener = result => { - // console.log("customMessageListener:" + JSON.stringify(result)) - // }; - // JPush.addCustomMessagegListener(this.customMessageListener); - //tag alias事件回调 - this.tagAliasListener = result => { - console.log("tagAliasListener:" + JSON.stringify(result)) - }; - JPush.addTagAliasListener(this.tagAliasListener); - //手机号码事件回调 - this.mobileNumberListener = result => { - console.log("mobileNumberListener:" + JSON.stringify(result)) - }; - JPush.addMobileNumberListener(this.mobileNumberListener); - } - - render() { - return ( - -