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

Commit

Permalink
Merge pull request #19 from Jeepeng/develop
Browse files Browse the repository at this point in the history
Release v0.7
  • Loading branch information
Jeepeng authored May 28, 2018
2 parents fe2b41c + ef295e4 commit b3e6474
Show file tree
Hide file tree
Showing 13 changed files with 1,793 additions and 1,721 deletions.
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
- [x] 适配华为官方推送通道
- [x] 适配小米官方推送通道
- [x] 适配魅族官方推送通道
- [ ] 升级信鸽iOS SDK 到 v3.1.0
- [x] 升级信鸽iOS SDK 到 v3.1.0

## 版本对照表
react-native-xinge-push | 信鸽SDK(Android) | 信鸽SDK(iOS)
---|---|---
0.6 | 3.2.2 | 3.1.1
0.4~0.5 | 3.2.2 | 2.5.0
0.3 | 3.1.0 | 2.5.0

Expand Down Expand Up @@ -88,13 +89,26 @@ AppDelegate.m:
return YES;
}
// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[XGPushManager didRegisterUserNotificationSettings:notificationSettings];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"[XGDemo] device token is %@", [[XGPushTokenManager defaultTokenManager] deviceTokenString]);
[XGPushManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"[XGDemo] register APNS fail.\n[XGDemo] reason : %@", error);
[[NSNotificationCenter defaultCenter] postNotificationName:@"registerDeviceFailed" object:nil];
NSLog(@"[XGPush] register APNS fail.\n[XGPush] reason : %@", error);
[XGPushManager didFailToRegisterForRemoteNotificationsWithError:error];
}
// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[XGPushManager didReceiveLocalNotification:notification];
}
/**
Expand All @@ -105,8 +119,8 @@ AppDelegate.m:
@param completionHandler 完成回调
*/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"[XGDemo] receive slient Notification");
NSLog(@"[XGDemo] userinfo %@", userInfo);
NSLog(@"[XGPush] receive slient Notification");
NSLog(@"[XGPush] userinfo %@", userInfo);
UIApplicationState state = [application applicationState];
BOOL isClicked = (state != UIApplicationStateActive);
NSMutableDictionary *remoteNotification = [NSMutableDictionary dictionaryWithDictionary:userInfo];
Expand All @@ -115,7 +129,7 @@ AppDelegate.m:
remoteNotification[@"background"] = @YES;
}
[[XGPush defaultManager] reportXGNotificationInfo:remoteNotification];
completionHandler(UIBackgroundFetchResultNewData);
[XGPushManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}
// iOS 10 新增 API
Expand All @@ -126,7 +140,7 @@ AppDelegate.m:
// App 用户在通知中心清除消息
// 无论本地推送还是远程推送都会走这个回调
- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
NSLog(@"[XGDemo] click notification");
NSLog(@"[XGPush] click notification");
if ([response.actionIdentifier isEqualToString:@"xgaction001"]) {
NSLog(@"click from Action1");
} else if ([response.actionIdentifier isEqualToString:@"xgaction002"]) {
Expand Down
10 changes: 5 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 26
buildToolsVersion '26.0.3'
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 16
Expand Down Expand Up @@ -31,10 +31,10 @@ dependencies {
testCompile 'junit:junit:4.12'
compile "com.facebook.react:react-native:+"
compile "me.leolin:ShortcutBadger:1.1.21@aar"
compile 'com.tencent.xinge:xinge:3.2.2-release'
compile 'com.tencent.xinge:xinge:3.2.4-beta'
compile 'com.tencent.wup:wup:1.0.0.E-release'
compile 'com.tencent.mid:mid:4.0.6-release'
compile 'com.tencent.xinge:xghw:2.5.2.300-release'
compile 'com.tencent.xinge:mipush:3.2.2-release'
compile 'com.tencent.xinge:xgmz:3.2.2-release'
compile 'com.tencent.xinge:xghw:3.2.4-beta'
compile 'com.tencent.xinge:mipush:3.2.4-beta'
compile 'com.tencent.xinge:xgmz:3.2.4-beta'
}
6 changes: 3 additions & 3 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<action android:name="com.tencent.android.tpush.action.FEEDBACK" />
</intent-filter>
</receiver>
<receiver android:name="com.jeepeng.react.xgpush.receiver.HWMessageReceiver" >
<receiver android:name="com.tencent.android.hwpush.HWPushMessageReceiver" >
<intent-filter>
<!-- 必须,用于接收TOKEN -->
<action android:name="com.huawei.android.push.intent.REGISTRATION" />
Expand All @@ -28,7 +28,7 @@
</receiver>
<receiver
android:exported="true"
android:name="com.jeepeng.react.xgpush.receiver.XMMessageReceiver">
android:name="com.tencent.android.mipush.XMPushMessageReceiver">
<intent-filter>
<action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" />
</intent-filter>
Expand All @@ -39,7 +39,7 @@
<action android:name="com.xiaomi.mipush.ERROR" />
</intent-filter>
</receiver>
<receiver android:name="com.jeepeng.react.xgpush.receiver.MZMessageReceiver">
<receiver android:name="com.tencent.android.mzpush.MZPushMessageReceiver">
<intent-filter>
<!-- 接收push消息 -->
<action android:name="com.meizu.flyme.push.intent.MESSAGE" />
Expand Down
10 changes: 8 additions & 2 deletions android/src/main/java/com/jeepeng/react/xgpush/PushModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGLocalMessage;
import com.tencent.android.tpush.XGPushClickedResult;
import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;
import com.tencent.android.tpush.encrypt.Rijndael;
Expand Down Expand Up @@ -371,8 +372,13 @@ public void initMeizu(String appId, String appKey) {
public void getInitialNotification(Promise promise) {
WritableMap params = Arguments.createMap();
Activity activity = getCurrentActivity();
Log.d("getInitialNotification", ">>>>>>>>>>>>>>>>>");
if (activity != null) {
Intent intent = activity.getIntent();
XGPushClickedResult result = XGPushManager.onActivityStarted(activity);
if (result != null) {
Log.d("getInitialNotification", result.getContent());
}
try {
if(intent != null && intent.hasExtra("protect")) {
String title = Rijndael.decrypt(intent.getStringExtra("title"));
Expand All @@ -381,6 +387,7 @@ public void getInitialNotification(Promise promise) {
params.putString("title", title);
params.putString("content", content);
params.putString("custom_content", customContent);
Log.d("getInitialNotification", content);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -422,11 +429,10 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,

@Override
public void onNewIntent(Intent intent) {
/*
Log.d("onNewIntent", ">>>>>>>>>>>>>>>>>");
Activity activity = getCurrentActivity();
if (activity != null) {
activity.setIntent(intent); // 后台运行时点击通知会调用
}
*/
}
}
Original file line number Diff line number Diff line change
@@ -1,101 +1,11 @@
package com.jeepeng.react.xgpush.receiver;

import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;

import com.huawei.hms.support.api.push.PushReceiver;
import com.jeepeng.react.xgpush.Constants;

import java.io.FileWriter;
import java.io.IOException;
import com.tencent.android.hwpush.HWPushMessageReceiver;

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

public class HWMessageReceiver extends PushReceiver {

@Override
public void onEvent(Context context, Event event, Bundle extras) {
if (Event.NOTIFICATION_OPENED.equals(event) || Event.NOTIFICATION_CLICK_BTN.equals(event)) {
int notifyId = extras.getInt(BOUND_KEY.pushNotifyId, 0);
if (0 != notifyId) {
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
manager.cancel(notifyId);
}
}

String message = extras.getString(BOUND_KEY.pushMsgKey);
String deviceToken = extras.getString(BOUND_KEY.deviceTokenKey);
int receiveType = extras.getInt(BOUND_KEY.receiveTypeKey);
String pushState = extras.getString(BOUND_KEY.pushStateKey);
int pushNotifyId = extras.getInt(BOUND_KEY.pushNotifyId, 0);
// message:[{"id":"123456"}]
// Bundle[{receiveType=4, pushMsg=[{"id":"1"},{"name":"jeepeng"},{"sex":"man"}]}]

if (Event.NOTIFICATION_OPENED.equals(event)) {
// 通知在通知栏被点击啦。。。。。
Intent intent = new Intent(Constants.ACTION_ON_NOTIFICATION_CLICKED);
Bundle bundle = new Bundle();
bundle.putString("content", message);
intent.putExtra("notification", bundle);

intent.putExtra("content", message);
intent.putExtra("custom_content", message);
context.sendBroadcast(intent);
}

super.onEvent(context, event, extras);
}

@Override
public boolean onPushMsg(Context context, byte[] msg, Bundle bundle) {
try {
String content = new String(msg, "UTF-8");
Intent intent = new Intent(Constants.ACTION_ON_TEXT_MESSAGE);
intent.putExtra("content", content);
context.sendBroadcast(intent);
System.out.println(bundle);
Log.i("HWMessageReceiver", "收到PUSH透传消息,消息内容为:" + content);
} catch (Exception e) {
e.printStackTrace();
}
return super.onPushMsg(context, msg, bundle);
}

@Override
public void onPushState(Context context, boolean pushState) {
super.onPushState(context, pushState);
}

@Override
public void onToken(Context context, String token, Bundle extras) {
super.onToken(context, token, extras);
}

@Override
public void onToken(Context context, String token) {
super.onToken(context, token);
}

private void writeToFile(String conrent) {
String SDPATH = Environment.getExternalStorageDirectory() + "/huawei.txt";
try {
FileWriter fileWriter = new FileWriter(SDPATH, true);

fileWriter.write(conrent+"\r\n");
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


public class HWMessageReceiver extends HWPushMessageReceiver {
}
11 changes: 6 additions & 5 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,23 @@ def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
compileSdkVersion 25
buildToolsVersion '26.0.3'
compileSdkVersion 26
buildToolsVersion '27.0.3'

defaultConfig {
applicationId "com.jeepeng.push"
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 26
versionCode 3
versionName "1.0"
versionName "1.0.1"
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [
XG_ACCESS_ID: "2100209996",
XG_ACCESS_KEY: "AHW931HVZ42A",
HW_APPID: "100225811",
PACKAGE_NAME: "com.jeepeng.push"
]
}
splits {
Expand Down Expand Up @@ -144,7 +145,7 @@ android {
dependencies {
compile project(':react-native-xinge-push')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:25.4.0"
compile "com.android.support:appcompat-v7:26.1.0"
compile "com.facebook.react:react-native:+" // From node_modules
}

Expand Down
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Jan 17 12:01:37 CST 2018
#Tue Mar 27 17:51:16 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
27 changes: 20 additions & 7 deletions example/ios/example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,26 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

// Required to register for notifications
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[XGPushManager didRegisterUserNotificationSettings:notificationSettings];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"[XGDemo] device token is %@", [[XGPushTokenManager defaultTokenManager] deviceTokenString]);
[XGPushManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

// Required for the registrationError event.
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"[XGDemo] register APNS fail.\n[XGDemo] reason : %@", error);
[[NSNotificationCenter defaultCenter] postNotificationName:@"registerDeviceFailed" object:nil];
NSLog(@"[XGPush] register APNS fail.\n[XGPush] reason : %@", error);
[XGPushManager didFailToRegisterForRemoteNotificationsWithError:error];
}

// Required for the localNotification event.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[XGPushManager didReceiveLocalNotification:notification];
}

/**
Expand All @@ -55,8 +68,8 @@ - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotif
@param completionHandler 完成回调
*/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"[XGDemo] receive slient Notification");
NSLog(@"[XGDemo] userinfo %@", userInfo);
NSLog(@"[XGPush] receive slient Notification");
NSLog(@"[XGPush] userinfo %@", userInfo);
UIApplicationState state = [application applicationState];
BOOL isClicked = (state != UIApplicationStateActive);
NSMutableDictionary *remoteNotification = [NSMutableDictionary dictionaryWithDictionary:userInfo];
Expand All @@ -65,7 +78,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N
remoteNotification[@"background"] = @YES;
}
[[XGPush defaultManager] reportXGNotificationInfo:remoteNotification];
completionHandler(UIBackgroundFetchResultNewData);
[XGPushManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
}

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

0 comments on commit b3e6474

Please sign in to comment.