Skip to content

Commit f7ddd53

Browse files
ByteZhang1024huangshuniLcTerrylcTerryweiry
authored
Feat/update jpush (#9)
* fix addCustomMessageListener 方法报错问题 * 更新Jpush4.8.1,新增对外API:设置用户属性。对外版本号293, * 更新iOS Jpush4.8.1,新增对外API:设置用户属性。对外版本号294 * 解决iOS 杀死状态点击通知进入app没有回调通知的问题 * 更新Jpush4.8.3,对外版本号295, * 更新清单文件配置+版本296 * 更新清单文件配置+版本297 * 【iOS】解决没有初始化,但是会请求通知权限弹窗的问题 * 升级iOS jpush SDK到4.9.0, 更新插件版本号为2.9.8 * 更新JPush 500 * 【iOS】更新到jpush5.0.0 * 【ios】fix * 更新JPush 500:适配新回调 * 更新demo的jcore版本,fixdemo警告 * 更新JPush 504,对外版本号2.9.9 * 开放:setChannelAndSound * 更新版本号3.0.0 * 开放本地通知定时展示字段 * ios 开放本地通知定时展示字段 * 更新版本号3.0.1 * ios 开放本地通知定时展示字段fix,修改版本号为3.0.2 * iOS新增获取通知权限开关的接口,修改版本号为3.0.3 * 修改init参数channel名 * 更新版本号3.0.4 + 暴露CommandEvent 回调 * 更新JPush 520 * iOS 更新SDK为520 * 更新版本号3.0.5 * iOS 更新SDK为530, 版本号更新为3.0.5 * 修改清单文件配置 * 更新版本号3.0.6 * 更新版本号为3.0.7 * 修改版本号为3.0.8 * 更新版适配rn 0.74 * 更新版 版本号3.0.7 * 补充iOS appdelegate.m 中的代码 * 更新版JPush 540 版本号3.1.0 * ios demo更新 * demo更新 * 修改安卓demo * 更新安卓demo * 修复Android studio run 报错 * 删除,否则界面新加功能后,显示还是老的 * ios SDK更新到5.4.0版本 * 更新JPush 550+版本号3.1.1 * 更新demo使用插件版本 * iOS 修复jpush的代理设置问题。 * 更新版本号为3.1.2 * iOS 更新到jpush550 * 更新JPush 560+版本号3.1.2 * ts中新增addCommandEventListener +版本号3.1.4 * ios 更新到jpush560, JPush.podspec 改为JPushRN.podspec。 * 版本号改为3.1.5 * 更新demo * android更新JPush 570+版本号3.1.6+新增setDataInsightsEnable接口 * 修复 iOS bool 问题 * fix 安卓点击通知不回调问题,更新版本号为3.1.8 * 新增cursor快速更新模版文档 * 本地通知添加category、priority、builderName属性 * 本地通知添加category、priority、builderName属性 * 本地通知添加category、priority、builderName属性 * 本地通知添加category、priority、builderName属性 * 本地通知添加category、priority、builderName属性 * 3.2.0:android 5.8.0 ios 5.7.0 * 添加iOS-Swift代码示例 * 3.2.1:android 5.9.0 ios 5.9.0 * chore: update jpush --------- Co-authored-by: huangshuni <[email protected]> Co-authored-by: Lcterry <[email protected]> Co-authored-by: lcTerry <[email protected]> Co-authored-by: weiry <[email protected]>
1 parent f10dfb5 commit f7ddd53

File tree

93 files changed

+5413
-1512
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+5413
-1512
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
example/
2+
cursor.md

JPush.podspec renamed to JPushRN.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pjson = JSON.parse(File.read('package.json'))
33

44
Pod::Spec.new do |s|
55

6-
s.name = "JPush"
6+
s.name = "JPushRN"
77
s.version = pjson["version"]
88
s.homepage = pjson["homepage"]
99
s.summary = pjson["description"]
@@ -18,6 +18,6 @@ Pod::Spec.new do |s|
1818
s.frameworks = 'UIKit','CFNetwork','CoreFoundation','CoreTelephony','SystemConfiguration','CoreGraphics','Foundation','Security'
1919
s.weak_frameworks = 'UserNotifications'
2020
s.libraries = 'z','resolv'
21-
s.vendored_libraries = "ios/RCTJPushModule/*.a"
21+
s.vendored_frameworks = "ios/RCTJPushModule/*.xcframework"
2222
s.dependency 'React'
2323
end

android/build.gradle

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ def safeExtGet(prop, fallback) {
55
}
66

77
android {
8-
compileSdkVersion safeExtGet('compileSdkVersion', 27)
8+
compileSdkVersion safeExtGet('compileSdkVersion', 34)
9+
10+
namespace 'cn.jiguang.plugins.push'
11+
912
defaultConfig {
10-
minSdkVersion safeExtGet('minSdkVersion', 16)
11-
targetSdkVersion safeExtGet('targetSdkVersion', 27)
13+
minSdkVersion safeExtGet('minSdkVersion', 23)
14+
targetSdkVersion safeExtGet('targetSdkVersion', 34)
1215
versionCode 1
1316
versionName "1.0"
1417

-638 KB
Binary file not shown.
399 KB
Binary file not shown.

android/src/main/AndroidManifest.xml

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="cn.jiguang.plugins.push">
2+
>
33

44
<permission
55
android:name="${applicationId}.permission.JPUSH_MESSAGE"
66
android:protectionLevel="signature" />
7-
87
<!-- Required -->
98
<uses-permission android:name="${applicationId}.permission.JPUSH_MESSAGE" />
10-
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
119
<uses-permission android:name="android.permission.INTERNET" />
10+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
11+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
12+
<!--华为角标-->
13+
<uses-permission android:name="com.huawei.android.launcher.permission.CHANGE_BADGE"/>
14+
<!--vivo 角标-->
15+
<uses-permission android:name="com.vivo.notification.permission.BADGE_ICON" />
16+
<!--honor 角标-->
17+
<uses-permission android:name="com.hihonor.android.launcher.permission.CHANGE_BADGE" />
18+
<!--小米 推送必须-->
19+
<uses-permission android:name="android.permission.VIBRATE" />
20+
<!-- Optional. Required for location feature -->
21+
<!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
22+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
23+
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
1224
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
25+
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
26+
<uses-permission android:name="android.permission.GET_TASKS" />
27+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
1328
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1429
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
1530
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
1631
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
17-
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
18-
19-
<!-- Optional. Required for location feature -->
20-
<!-- <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
21-
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
22-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
23-
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
24-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
25-
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
26-
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
27-
<uses-permission android:name="android.permission.GET_TASKS" />
28-
<uses-permission android:name="android.permission.VIBRATE" />
29-
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> -->
32+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> -->
3033

3134
<application>
3235
<activity
3336
android:name="cn.jpush.android.ui.PopWinActivity"
34-
android:exported="false"
35-
android:theme="@style/MyDialogStyle" />
37+
android:exported="true"
38+
android:theme="@style/MyDialogStyle" >
39+
<intent-filter>
40+
<category android:name="android.intent.category.DEFAULT" />
41+
<action android:name="cn.jpush.android.ui.PopWinActivity" />
42+
<category android:name="${applicationId}" />
43+
</intent-filter>
44+
</activity>
3645

3746
<activity
3847
android:name="cn.jpush.android.ui.PushActivity"
@@ -50,7 +59,7 @@
5059
<activity
5160
android:name="cn.jpush.android.service.JNotifyActivity"
5261
android:exported="true"
53-
android:taskAffinity="jpush.custom"
62+
android:taskAffinity=""
5463
android:theme="@style/JPushTheme">
5564
<intent-filter>
5665
<action android:name="cn.jpush.android.intent.JNotifyActivity" />
@@ -63,7 +72,7 @@
6372
android:enabled="true"
6473
android:exported="false">
6574
<intent-filter>
66-
<action android:name="cn.jpush.android.intent.RECEIVE_MESSAGE" />
75+
<action android:name="cn.jpush.android.intent.RECEIVER_MESSAGE" />
6776
<category android:name="${applicationId}" />
6877
</intent-filter>
6978
</receiver>
@@ -83,7 +92,7 @@
8392
<activity
8493
android:name="cn.android.service.JTransitActivity"
8594
android:exported="true"
86-
android:taskAffinity="jpush.custom"
95+
android:taskAffinity=""
8796
android:theme="@style/JPushTheme" >
8897
<intent-filter>
8998
<action android:name="cn.android.service.JTransitActivity" />
@@ -95,13 +104,18 @@
95104
android:enabled="true"
96105
android:exported="true"
97106
android:theme="@android:style/Theme.Translucent.NoTitleBar"
98-
android:taskAffinity="jpush.custom">
107+
android:taskAffinity="">
99108
<intent-filter>
100109
<action android:name="cn.jpush.android.intent.DActivity"/>
101110
<category android:name="${applicationId}" />
102111
</intent-filter>
103112
</activity>
104-
113+
<provider
114+
android:name="cn.jpush.android.service.InitProvider"
115+
android:authorities="${applicationId}.jiguang.InitProvider"
116+
android:exported="false"
117+
android:readPermission="${applicationId}.permission.JPUSH_MESSAGE"
118+
android:writePermission="${applicationId}.permission.JPUSH_MESSAGE" />
105119
</application>
106120

107121
</manifest>

android/src/main/java/cn/jiguang/plugins/push/JPushModule.java

Lines changed: 182 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
package cn.jiguang.plugins.push;
3-
3+
import android.app.NotificationChannel;
4+
import android.app.NotificationManager;
5+
import android.net.Uri;
6+
import android.os.Build;
47
import android.app.Activity;
58
import android.app.Application;
69
import android.os.Bundle;
@@ -14,19 +17,23 @@
1417
import com.facebook.react.bridge.ReactMethod;
1518
import com.facebook.react.bridge.ReadableArray;
1619
import com.facebook.react.bridge.ReadableMap;
20+
import com.facebook.react.bridge.ReadableNativeMap;
1721
import com.facebook.react.bridge.WritableMap;
1822

1923
import org.json.JSONObject;
2024

25+
import java.util.HashMap;
2126
import java.util.HashSet;
2227
import java.util.Set;
28+
import java.lang.*;
2329

2430
import cn.jiguang.plugins.push.common.JConstants;
2531
import cn.jiguang.plugins.push.common.JLogger;
2632
import cn.jiguang.plugins.push.helper.JPushHelper;
2733
import cn.jiguang.plugins.push.receiver.JPushBroadcastReceiver;
2834
import cn.jpush.android.api.BasicPushNotificationBuilder;
2935
import cn.jpush.android.api.JPushInterface;
36+
import cn.jpush.android.data.JPushCollectControl;
3037
import cn.jpush.android.data.JPushLocalNotification;
3138

3239
public class JPushModule extends ReactContextBaseJavaModule {
@@ -59,6 +66,7 @@ public void init() {
5966
JPushHelper.sendEvent(JConstants.NOTIFICATION_EVENT, writableMap);
6067
JPushBroadcastReceiver.NOTIFICATION_BUNDLE = null;
6168
}
69+
JPushInterface.setNotificationCallBackEnable(reactContext,true);
6270
}
6371

6472
@ReactMethod
@@ -95,6 +103,92 @@ public void setChannel(ReadableMap readableMap) {
95103
}
96104
}
97105
@ReactMethod
106+
public void setChannelAndSound(ReadableMap readableMap) {
107+
if (readableMap == null) {
108+
JLogger.w(JConstants.PARAMS_NULL);
109+
return;
110+
}
111+
String channel = readableMap.getString(JConstants.CHANNEL);
112+
String sound = readableMap.getString(JConstants.SOUND);
113+
String channelId = readableMap.getString(JConstants.CHANNELID);
114+
try {
115+
NotificationManager manager= (NotificationManager) reactContext.getSystemService("notification");
116+
if(Build.VERSION.SDK_INT<26){
117+
return;
118+
}
119+
if(TextUtils.isEmpty(channel)||TextUtils.isEmpty(channelId)){
120+
return;
121+
}
122+
NotificationChannel channel1=new NotificationChannel(channelId,channel, NotificationManager.IMPORTANCE_HIGH);
123+
if(!TextUtils.isEmpty(sound)){
124+
channel1.setSound(Uri.parse("android.resource://"+reactContext.getPackageName()+"/raw/"+sound),null);
125+
}
126+
manager.createNotificationChannel(channel1);
127+
JPushInterface.setChannel(reactContext,channel);
128+
}catch (Throwable throwable){
129+
}
130+
}
131+
@ReactMethod
132+
public void setLinkMergeEnable(boolean enable) {
133+
JPushInterface.setLinkMergeEnable(reactContext, enable);
134+
}
135+
136+
@ReactMethod
137+
public void setSmartPushEnable(boolean enable) {
138+
JPushInterface.setSmartPushEnable(reactContext, enable);
139+
}
140+
141+
@ReactMethod
142+
public void setDataInsightsEnable(boolean enable) {
143+
JPushInterface.setDataInsightsEnable(reactContext, enable);
144+
}
145+
146+
@ReactMethod
147+
public void setGeofenceEnable(boolean enable) {
148+
JPushInterface.setGeofenceEnable(reactContext, enable);
149+
}
150+
151+
@ReactMethod
152+
public void setCollectControl(ReadableMap readableMap) {
153+
if (readableMap == null) {
154+
JLogger.w(JConstants.PARAMS_NULL);
155+
return;
156+
}
157+
boolean hadValue = false;
158+
JPushCollectControl.Builder builder = new JPushCollectControl.Builder();
159+
if (readableMap.hasKey(JConstants.IMEI)) {
160+
hadValue = true;
161+
builder.imei(readableMap.getBoolean(JConstants.IMEI));
162+
}
163+
if (readableMap.hasKey(JConstants.IMSI)) {
164+
hadValue = true;
165+
builder.imsi(readableMap.getBoolean(JConstants.IMSI));
166+
}
167+
if (readableMap.hasKey(JConstants.MAC)) {
168+
hadValue = true;
169+
builder.mac(readableMap.getBoolean(JConstants.MAC));
170+
}
171+
if (readableMap.hasKey(JConstants.WIFI)) {
172+
hadValue = true;
173+
builder.wifi(readableMap.getBoolean(JConstants.WIFI));
174+
}
175+
if (readableMap.hasKey(JConstants.BSSID)) {
176+
hadValue = true;
177+
builder.bssid(readableMap.getBoolean(JConstants.BSSID));
178+
}
179+
if (readableMap.hasKey(JConstants.SSID)) {
180+
hadValue = true;
181+
builder.ssid(readableMap.getBoolean(JConstants.SSID));
182+
}
183+
if (readableMap.hasKey(JConstants.CELL)) {
184+
hadValue = true;
185+
builder.cell(readableMap.getBoolean(JConstants.CELL));
186+
}
187+
if (hadValue) {
188+
JPushInterface.setCollectControl(reactContext, builder.build());
189+
}
190+
}
191+
@ReactMethod
98192
public void setBadgeNumber(ReadableMap readableMap) {
99193
if (readableMap == null) {
100194
JLogger.w(JConstants.PARAMS_NULL);
@@ -213,7 +307,48 @@ public void filterValidTags(ReadableMap readableMap, Callback callback) {
213307
JLogger.w("there are no " + JConstants.TAGS);
214308
}
215309
}
310+
@ReactMethod
311+
public void setProperties(ReadableMap readableMap) {
312+
if (readableMap == null) {
313+
JLogger.w(JConstants.PARAMS_NULL);
314+
return;
315+
}
316+
if (readableMap.hasKey(JConstants.PROPERTIES)) {
317+
int sequence = readableMap.getInt(JConstants.SEQUENCE);
318+
ReadableMap readMap = readableMap.getMap(JConstants.PROPERTIES);
319+
ReadableNativeMap map= (ReadableNativeMap) readMap;
320+
HashMap properties=map.toHashMap();
321+
JPushInterface.setProperties(reactContext,sequence,properties);
322+
} else {
323+
JLogger.w("there are no " + JConstants.PROPERTIES);
324+
}
325+
}
326+
@ReactMethod
327+
public void deleteProperties(ReadableMap readableMap) {
328+
if (readableMap == null) {
329+
JLogger.w(JConstants.PARAMS_NULL);
330+
return;
331+
}
332+
if (readableMap.hasKey(JConstants.PROPERTIES)) {
333+
int sequence = readableMap.getInt(JConstants.SEQUENCE);
334+
ReadableMap readMap = readableMap.getMap(JConstants.PROPERTIES);
335+
ReadableNativeMap map= (ReadableNativeMap) readMap;
336+
HashMap properties=map.toHashMap();
337+
JPushInterface.deleteProperties(reactContext,sequence,properties);
338+
} else {
339+
JLogger.w("there are no " + JConstants.PROPERTIES);
340+
}
216341

342+
}
343+
@ReactMethod
344+
public void cleanProperties(ReadableMap readableMap) {
345+
if (readableMap == null) {
346+
JLogger.w(JConstants.PARAMS_NULL);
347+
return;
348+
}
349+
int sequence = readableMap.getInt(JConstants.SEQUENCE);
350+
JPushInterface.cleanProperties(reactContext,sequence);
351+
}
217352
@ReactMethod
218353
public void setTags(ReadableMap readableMap) {
219354
if (readableMap == null) {
@@ -390,15 +525,61 @@ public void addLocalNotification(ReadableMap readableMap) {
390525
int id = Integer.valueOf(notificationID);
391526
String notificationTitle = readableMap.hasKey(JConstants.TITLE) ? readableMap.getString(JConstants.TITLE) : reactContext.getPackageName();
392527
String notificationContent = readableMap.hasKey(JConstants.CONTENT) ? readableMap.getString(JConstants.CONTENT) : reactContext.getPackageName();
528+
String broadcastTime = readableMap.hasKey(JConstants.BROADCAST_TIME) ? readableMap.getString(JConstants.BROADCAST_TIME) : "0";
393529
JPushLocalNotification notification = new JPushLocalNotification();
394530
notification.setNotificationId(id);
395531
notification.setTitle(notificationTitle);
396532
notification.setContent(notificationContent);
533+
try {
534+
notification.setBroadcastTime(Long.parseLong(broadcastTime));
535+
}catch (Throwable throwable){
536+
}
397537
if (readableMap.hasKey(JConstants.EXTRAS)) {
398538
ReadableMap notificationExtra = readableMap.getMap(JConstants.EXTRAS);
399539
JSONObject notificationExtraJson = new JSONObject(notificationExtra.toHashMap());
400540
notification.setExtras(notificationExtraJson.toString());
401541
}
542+
543+
// 设置BuilderId
544+
if (readableMap.hasKey(JConstants.BUILDER_NAME)) {
545+
try {
546+
String layoutFileName = readableMap.getString(JConstants.BUILDER_NAME);
547+
if (!TextUtils.isEmpty(layoutFileName)) {
548+
// 通过布局文件名获取资源ID
549+
int builderId = reactContext.getResources().getIdentifier(
550+
layoutFileName,
551+
"layout",
552+
reactContext.getPackageName()
553+
);
554+
if (builderId != 0) {
555+
notification.setBuilderId(builderId);
556+
} else {
557+
JLogger.w("Layout file not found: " + layoutFileName);
558+
}
559+
}
560+
} catch (Exception e) {
561+
JLogger.w("Failed to set BuilderId: " + e.getMessage());
562+
}
563+
}
564+
565+
// 设置Category
566+
if (readableMap.hasKey(JConstants.CATEGORY)) {
567+
String category = readableMap.getString(JConstants.CATEGORY);
568+
if (!TextUtils.isEmpty(category)) {
569+
notification.setCategory(category);
570+
}
571+
}
572+
573+
// 设置Priority
574+
if (readableMap.hasKey(JConstants.PRIORITY)) {
575+
try {
576+
int priority = readableMap.getInt(JConstants.PRIORITY);
577+
notification.setPriority(priority);
578+
} catch (Exception e) {
579+
JLogger.w("Priority must be a number");
580+
}
581+
}
582+
402583
JPushInterface.addLocalNotification(reactContext, notification);
403584
}
404585

0 commit comments

Comments
 (0)