Skip to content
This repository was archived by the owner on Apr 11, 2023. It is now read-only.

Commit b3e6474

Browse files
authored
Merge pull request #19 from Jeepeng/develop
Release v0.7
2 parents fe2b41c + ef295e4 commit b3e6474

File tree

13 files changed

+1793
-1721
lines changed

13 files changed

+1793
-1721
lines changed

README.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
- [x] 适配华为官方推送通道
44
- [x] 适配小米官方推送通道
55
- [x] 适配魅族官方推送通道
6-
- [ ] 升级信鸽iOS SDK 到 v3.1.0
6+
- [x] 升级信鸽iOS SDK 到 v3.1.0
77

88
## 版本对照表
99
react-native-xinge-push | 信鸽SDK(Android) | 信鸽SDK(iOS)
1010
---|---|---
11+
0.6 | 3.2.2 | 3.1.1
1112
0.4~0.5 | 3.2.2 | 2.5.0
1213
0.3 | 3.1.0 | 2.5.0
1314

@@ -88,13 +89,26 @@ AppDelegate.m:
8889
return YES;
8990
}
9091
92+
// Required to register for notifications
93+
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
94+
{
95+
[XGPushManager didRegisterUserNotificationSettings:notificationSettings];
96+
}
97+
9198
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
92-
NSLog(@"[XGDemo] device token is %@", [[XGPushTokenManager defaultTokenManager] deviceTokenString]);
99+
[XGPushManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
93100
}
94101
102+
// Required for the registrationError event.
95103
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
96-
NSLog(@"[XGDemo] register APNS fail.\n[XGDemo] reason : %@", error);
97-
[[NSNotificationCenter defaultCenter] postNotificationName:@"registerDeviceFailed" object:nil];
104+
NSLog(@"[XGPush] register APNS fail.\n[XGPush] reason : %@", error);
105+
[XGPushManager didFailToRegisterForRemoteNotificationsWithError:error];
106+
}
107+
108+
// Required for the localNotification event.
109+
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
110+
{
111+
[XGPushManager didReceiveLocalNotification:notification];
98112
}
99113
100114
/**
@@ -105,8 +119,8 @@ AppDelegate.m:
105119
@param completionHandler 完成回调
106120
*/
107121
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
108-
NSLog(@"[XGDemo] receive slient Notification");
109-
NSLog(@"[XGDemo] userinfo %@", userInfo);
122+
NSLog(@"[XGPush] receive slient Notification");
123+
NSLog(@"[XGPush] userinfo %@", userInfo);
110124
UIApplicationState state = [application applicationState];
111125
BOOL isClicked = (state != UIApplicationStateActive);
112126
NSMutableDictionary *remoteNotification = [NSMutableDictionary dictionaryWithDictionary:userInfo];
@@ -115,7 +129,7 @@ AppDelegate.m:
115129
remoteNotification[@"background"] = @YES;
116130
}
117131
[[XGPush defaultManager] reportXGNotificationInfo:remoteNotification];
118-
completionHandler(UIBackgroundFetchResultNewData);
132+
[XGPushManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
119133
}
120134
121135
// iOS 10 新增 API
@@ -126,7 +140,7 @@ AppDelegate.m:
126140
// App 用户在通知中心清除消息
127141
// 无论本地推送还是远程推送都会走这个回调
128142
- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
129-
NSLog(@"[XGDemo] click notification");
143+
NSLog(@"[XGPush] click notification");
130144
if ([response.actionIdentifier isEqualToString:@"xgaction001"]) {
131145
NSLog(@"click from Action1");
132146
} else if ([response.actionIdentifier isEqualToString:@"xgaction002"]) {

android/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.library'
22

33
android {
44
compileSdkVersion 26
5-
buildToolsVersion '26.0.3'
5+
buildToolsVersion '27.0.3'
66

77
defaultConfig {
88
minSdkVersion 16
@@ -31,10 +31,10 @@ dependencies {
3131
testCompile 'junit:junit:4.12'
3232
compile "com.facebook.react:react-native:+"
3333
compile "me.leolin:ShortcutBadger:1.1.21@aar"
34-
compile 'com.tencent.xinge:xinge:3.2.2-release'
34+
compile 'com.tencent.xinge:xinge:3.2.4-beta'
3535
compile 'com.tencent.wup:wup:1.0.0.E-release'
3636
compile 'com.tencent.mid:mid:4.0.6-release'
37-
compile 'com.tencent.xinge:xghw:2.5.2.300-release'
38-
compile 'com.tencent.xinge:mipush:3.2.2-release'
39-
compile 'com.tencent.xinge:xgmz:3.2.2-release'
37+
compile 'com.tencent.xinge:xghw:3.2.4-beta'
38+
compile 'com.tencent.xinge:mipush:3.2.4-beta'
39+
compile 'com.tencent.xinge:xgmz:3.2.4-beta'
4040
}

android/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<action android:name="com.tencent.android.tpush.action.FEEDBACK" />
1515
</intent-filter>
1616
</receiver>
17-
<receiver android:name="com.jeepeng.react.xgpush.receiver.HWMessageReceiver" >
17+
<receiver android:name="com.tencent.android.hwpush.HWPushMessageReceiver" >
1818
<intent-filter>
1919
<!-- 必须,用于接收TOKEN -->
2020
<action android:name="com.huawei.android.push.intent.REGISTRATION" />
@@ -28,7 +28,7 @@
2828
</receiver>
2929
<receiver
3030
android:exported="true"
31-
android:name="com.jeepeng.react.xgpush.receiver.XMMessageReceiver">
31+
android:name="com.tencent.android.mipush.XMPushMessageReceiver">
3232
<intent-filter>
3333
<action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" />
3434
</intent-filter>
@@ -39,7 +39,7 @@
3939
<action android:name="com.xiaomi.mipush.ERROR" />
4040
</intent-filter>
4141
</receiver>
42-
<receiver android:name="com.jeepeng.react.xgpush.receiver.MZMessageReceiver">
42+
<receiver android:name="com.tencent.android.mzpush.MZPushMessageReceiver">
4343
<intent-filter>
4444
<!-- 接收push消息 -->
4545
<action android:name="com.meizu.flyme.push.intent.MESSAGE" />

android/src/main/java/com/jeepeng/react/xgpush/PushModule.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.facebook.react.modules.core.DeviceEventManagerModule;
2121
import com.tencent.android.tpush.XGIOperateCallback;
2222
import com.tencent.android.tpush.XGLocalMessage;
23+
import com.tencent.android.tpush.XGPushClickedResult;
2324
import com.tencent.android.tpush.XGPushConfig;
2425
import com.tencent.android.tpush.XGPushManager;
2526
import com.tencent.android.tpush.encrypt.Rijndael;
@@ -371,8 +372,13 @@ public void initMeizu(String appId, String appKey) {
371372
public void getInitialNotification(Promise promise) {
372373
WritableMap params = Arguments.createMap();
373374
Activity activity = getCurrentActivity();
375+
Log.d("getInitialNotification", ">>>>>>>>>>>>>>>>>");
374376
if (activity != null) {
375377
Intent intent = activity.getIntent();
378+
XGPushClickedResult result = XGPushManager.onActivityStarted(activity);
379+
if (result != null) {
380+
Log.d("getInitialNotification", result.getContent());
381+
}
376382
try {
377383
if(intent != null && intent.hasExtra("protect")) {
378384
String title = Rijndael.decrypt(intent.getStringExtra("title"));
@@ -381,6 +387,7 @@ public void getInitialNotification(Promise promise) {
381387
params.putString("title", title);
382388
params.putString("content", content);
383389
params.putString("custom_content", customContent);
390+
Log.d("getInitialNotification", content);
384391
}
385392
} catch (Exception e) {
386393
e.printStackTrace();
@@ -422,11 +429,10 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
422429

423430
@Override
424431
public void onNewIntent(Intent intent) {
425-
/*
432+
Log.d("onNewIntent", ">>>>>>>>>>>>>>>>>");
426433
Activity activity = getCurrentActivity();
427434
if (activity != null) {
428435
activity.setIntent(intent); // 后台运行时点击通知会调用
429436
}
430-
*/
431437
}
432438
}
Lines changed: 2 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,11 @@
11
package com.jeepeng.react.xgpush.receiver;
22

3-
import android.app.NotificationManager;
4-
import android.content.Context;
5-
import android.content.Intent;
6-
import android.os.Bundle;
7-
import android.os.Environment;
8-
import android.util.Log;
9-
10-
import com.huawei.hms.support.api.push.PushReceiver;
11-
import com.jeepeng.react.xgpush.Constants;
12-
13-
import java.io.FileWriter;
14-
import java.io.IOException;
3+
import com.tencent.android.hwpush.HWPushMessageReceiver;
154

165
/**
176
* 华为官方推送通道消息接收器
187
* Created by Jeepeng on 2018/3/11.
198
*/
209

21-
public class HWMessageReceiver extends PushReceiver {
22-
23-
@Override
24-
public void onEvent(Context context, Event event, Bundle extras) {
25-
if (Event.NOTIFICATION_OPENED.equals(event) || Event.NOTIFICATION_CLICK_BTN.equals(event)) {
26-
int notifyId = extras.getInt(BOUND_KEY.pushNotifyId, 0);
27-
if (0 != notifyId) {
28-
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
29-
manager.cancel(notifyId);
30-
}
31-
}
32-
33-
String message = extras.getString(BOUND_KEY.pushMsgKey);
34-
String deviceToken = extras.getString(BOUND_KEY.deviceTokenKey);
35-
int receiveType = extras.getInt(BOUND_KEY.receiveTypeKey);
36-
String pushState = extras.getString(BOUND_KEY.pushStateKey);
37-
int pushNotifyId = extras.getInt(BOUND_KEY.pushNotifyId, 0);
38-
// message:[{"id":"123456"}]
39-
// Bundle[{receiveType=4, pushMsg=[{"id":"1"},{"name":"jeepeng"},{"sex":"man"}]}]
40-
41-
if (Event.NOTIFICATION_OPENED.equals(event)) {
42-
// 通知在通知栏被点击啦。。。。。
43-
Intent intent = new Intent(Constants.ACTION_ON_NOTIFICATION_CLICKED);
44-
Bundle bundle = new Bundle();
45-
bundle.putString("content", message);
46-
intent.putExtra("notification", bundle);
47-
48-
intent.putExtra("content", message);
49-
intent.putExtra("custom_content", message);
50-
context.sendBroadcast(intent);
51-
}
52-
53-
super.onEvent(context, event, extras);
54-
}
55-
56-
@Override
57-
public boolean onPushMsg(Context context, byte[] msg, Bundle bundle) {
58-
try {
59-
String content = new String(msg, "UTF-8");
60-
Intent intent = new Intent(Constants.ACTION_ON_TEXT_MESSAGE);
61-
intent.putExtra("content", content);
62-
context.sendBroadcast(intent);
63-
System.out.println(bundle);
64-
Log.i("HWMessageReceiver", "收到PUSH透传消息,消息内容为:" + content);
65-
} catch (Exception e) {
66-
e.printStackTrace();
67-
}
68-
return super.onPushMsg(context, msg, bundle);
69-
}
70-
71-
@Override
72-
public void onPushState(Context context, boolean pushState) {
73-
super.onPushState(context, pushState);
74-
}
75-
76-
@Override
77-
public void onToken(Context context, String token, Bundle extras) {
78-
super.onToken(context, token, extras);
79-
}
80-
81-
@Override
82-
public void onToken(Context context, String token) {
83-
super.onToken(context, token);
84-
}
85-
86-
private void writeToFile(String conrent) {
87-
String SDPATH = Environment.getExternalStorageDirectory() + "/huawei.txt";
88-
try {
89-
FileWriter fileWriter = new FileWriter(SDPATH, true);
90-
91-
fileWriter.write(conrent+"\r\n");
92-
fileWriter.flush();
93-
fileWriter.close();
94-
} catch (IOException e) {
95-
// TODO Auto-generated catch block
96-
e.printStackTrace();
97-
}
98-
}
99-
100-
10+
public class HWMessageReceiver extends HWPushMessageReceiver {
10111
}

example/android/app/build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,23 @@ def enableSeparateBuildPerCPUArchitecture = false
9494
def enableProguardInReleaseBuilds = false
9595

9696
android {
97-
compileSdkVersion 25
98-
buildToolsVersion '26.0.3'
97+
compileSdkVersion 26
98+
buildToolsVersion '27.0.3'
9999

100100
defaultConfig {
101101
applicationId "com.jeepeng.push"
102102
minSdkVersion 16
103-
targetSdkVersion 25
103+
targetSdkVersion 26
104104
versionCode 3
105-
versionName "1.0"
105+
versionName "1.0.1"
106106
ndk {
107107
abiFilters "armeabi-v7a", "x86"
108108
}
109109
manifestPlaceholders = [
110110
XG_ACCESS_ID: "2100209996",
111111
XG_ACCESS_KEY: "AHW931HVZ42A",
112112
HW_APPID: "100225811",
113+
PACKAGE_NAME: "com.jeepeng.push"
113114
]
114115
}
115116
splits {
@@ -144,7 +145,7 @@ android {
144145
dependencies {
145146
compile project(':react-native-xinge-push')
146147
compile fileTree(dir: "libs", include: ["*.jar"])
147-
compile "com.android.support:appcompat-v7:25.4.0"
148+
compile "com.android.support:appcompat-v7:26.1.0"
148149
compile "com.facebook.react:react-native:+" // From node_modules
149150
}
150151

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
google()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:3.0.1'
9+
classpath 'com.android.tools.build:gradle:3.1.0'
1010

1111
// NOTE: Do not place your application dependencies here; they belong
1212
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Jan 17 12:01:37 CST 2018
1+
#Tue Mar 27 17:51:16 CST 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

example/ios/example/AppDelegate.m

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,26 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3838
return YES;
3939
}
4040

41+
// Required to register for notifications
42+
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
43+
{
44+
[XGPushManager didRegisterUserNotificationSettings:notificationSettings];
45+
}
46+
4147
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
42-
NSLog(@"[XGDemo] device token is %@", [[XGPushTokenManager defaultTokenManager] deviceTokenString]);
48+
[XGPushManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
4349
}
4450

51+
// Required for the registrationError event.
4552
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
46-
NSLog(@"[XGDemo] register APNS fail.\n[XGDemo] reason : %@", error);
47-
[[NSNotificationCenter defaultCenter] postNotificationName:@"registerDeviceFailed" object:nil];
53+
NSLog(@"[XGPush] register APNS fail.\n[XGPush] reason : %@", error);
54+
[XGPushManager didFailToRegisterForRemoteNotificationsWithError:error];
55+
}
56+
57+
// Required for the localNotification event.
58+
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
59+
{
60+
[XGPushManager didReceiveLocalNotification:notification];
4861
}
4962

5063
/**
@@ -55,8 +68,8 @@ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotif
5568
@param completionHandler 完成回调
5669
*/
5770
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
58-
NSLog(@"[XGDemo] receive slient Notification");
59-
NSLog(@"[XGDemo] userinfo %@", userInfo);
71+
NSLog(@"[XGPush] receive slient Notification");
72+
NSLog(@"[XGPush] userinfo %@", userInfo);
6073
UIApplicationState state = [application applicationState];
6174
BOOL isClicked = (state != UIApplicationStateActive);
6275
NSMutableDictionary *remoteNotification = [NSMutableDictionary dictionaryWithDictionary:userInfo];
@@ -65,7 +78,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N
6578
remoteNotification[@"background"] = @YES;
6679
}
6780
[[XGPush defaultManager] reportXGNotificationInfo:remoteNotification];
68-
completionHandler(UIBackgroundFetchResultNewData);
81+
[XGPushManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
6982
}
7083

7184
// iOS 10 新增 API
@@ -76,7 +89,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N
7689
// App 用户在通知中心清除消息
7790
// 无论本地推送还是远程推送都会走这个回调
7891
- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
79-
NSLog(@"[XGDemo] click notification");
92+
NSLog(@"[XGPush] click notification");
8093
if ([response.actionIdentifier isEqualToString:@"xgaction001"]) {
8194
NSLog(@"click from Action1");
8295
} else if ([response.actionIdentifier isEqualToString:@"xgaction002"]) {

0 commit comments

Comments
 (0)