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

fix bugs and unify the interfaces. #23

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ react-native link react-native-xinge-push
5. 再次进行单推/全推,如果能够收到推送,则表明厂商通道集成成功

###### 注意事项
消息目前将其理解为两类:静默消息和普通通知
静默消息不会弹窗,通知会弹窗

如果在EMUI 8.0(Android 8)上,出现发通知成功但通知栏不显示的情况,并在Logcat看到以下错误:
```
E/NotificationService: No Channel found for pkg=com.jeepeng.push, channelId=null, id=995033369, tag=null, opPkg=com.huawei.android.pushagent, callingUid=10060, userId=0, incomingUserId=0, notificationUid=10261, notification=Notification(channel=null pri=0 contentView=null vibrate=null sound=default tick defaults=0x1 flags=0x10 color=0x00000000 vis=PRIVATE)
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
manifestPlaceholders = [
XG_ACCESS_ID: "",
XG_ACCESS_KEY: "",
HW_APPID: "",
HW_APPID: ""
]
}

Expand Down
40 changes: 0 additions & 40 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,5 @@
<action android:name="com.tencent.android.tpush.action.FEEDBACK" />
</intent-filter>
</receiver>
<receiver android:name="com.tencent.android.hwpush.HWPushMessageReceiver" >
<intent-filter>
<!-- 必须,用于接收TOKEN -->
<action android:name="com.huawei.android.push.intent.REGISTRATION" />
<!-- 必须,用于接收消息 -->
<action android:name="com.huawei.android.push.intent.RECEIVE" />
<!-- 可选,用于点击通知栏或通知栏上的按钮后触发onEvent回调 -->
<action android:name="com.huawei.android.push.intent.CLICK" />
<!-- 可选,查看PUSH通道是否连接,不查看则不需要 -->
<action android:name="com.huawei.intent.action.PUSH_STATE" />
</intent-filter>
</receiver>
<receiver
android:exported="true"
android:name="com.tencent.android.mipush.XMPushMessageReceiver">
<intent-filter>
<action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" />
</intent-filter>
<intent-filter>
<action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" />
</intent-filter>
<intent-filter>
<action android:name="com.xiaomi.mipush.ERROR" />
</intent-filter>
</receiver>
<receiver android:name="com.tencent.android.mzpush.MZPushMessageReceiver">
<intent-filter>
<!-- 接收push消息 -->
<action android:name="com.meizu.flyme.push.intent.MESSAGE" />
<!-- 接收register消息-->
<action android:name="com.meizu.flyme.push.intent.REGISTER.FEEDBACK"/>
<!-- 接收unregister消息-->
<action android:name="com.meizu.flyme.push.intent.UNREGISTER.FEEDBACK"/>

<action android:name="com.meizu.c2dm.intent.REGISTRATION" />
<action android:name="com.meizu.c2dm.intent.RECEIVE" />

<category android:name="com.jeepeng.react.xgpush"/>
</intent-filter>
</receiver>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ public String getName() {
}

private void sendEvent(String eventName, @Nullable WritableMap params) {
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
if(getReactApplicationContext().hasActiveCatalystInstance()){
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
}

private void registerReceivers() {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ public void onNotifactionClickedResult(Context context, XGPushClickedResult noti
bundle.putString("title", notification.getTitle());
bundle.putString("custom_content", notification.getCustomContent());
intent.putExtra("notification", bundle);

intent.putExtra("title", notification.getTitle());
intent.putExtra("content", notification.getContent());
intent.putExtra("custom_content", notification.getCustomContent());
intent.putExtra("activity", notification.getActivityName());
intent.putExtra("msgId", notification.getMsgId());
intent.putExtra("notificationActionType", notification.getNotificationActionType());
Expand Down

This file was deleted.

4 changes: 3 additions & 1 deletion example/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Example extends Component {
}

initPush() {
XGPush.enableDebug(true)
// 初始化
if(Platform.OS === 'android') {
// 请将1111111111修改为APP的AccessId,10位数字
Expand Down Expand Up @@ -93,7 +94,7 @@ class Example extends Component {
* @private
*/
_onMessage(message) {
alert('收到透传消息: ' + message.content);
alert('收到透传消息: ' + JSON.stringify(message.content));
}

/**
Expand All @@ -102,6 +103,7 @@ class Example extends Component {
* @private
*/
_onNotification(notification) {
console.log(notification)
if(notification.clicked === true) {
alert('app处于后台时收到通知' + JSON.stringify(notification));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -83,6 +84,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
45 changes: 8 additions & 37 deletions example/ios/example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;

#ifdef DEBUG
[[RCTBundleURLProvider sharedSettings] setJsLocation:@"192.168.0.154"];
#endif
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
Expand Down Expand Up @@ -61,52 +63,21 @@ - (void)application:(UIApplication *)application didReceiveLocalNotification:(UI
}

/**
收到通知消息的回调,通常此消息意味着有新数据可以读取(iOS 7.0+)
收到静默消息的回调,通常此消息意味着有新数据可以读取(iOS 7.0+)

@param application UIApplication 实例
@param userInfo 推送时指定的参数
@param completionHandler 完成回调
*/
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"[XGPush] receive slient Notification");
NSLog(@"[XGPush] receive slient Message");
NSLog(@"[XGPush] userinfo %@", userInfo);
UIApplicationState state = [application applicationState];
BOOL isClicked = (state != UIApplicationStateActive);
NSMutableDictionary *remoteNotification = [NSMutableDictionary dictionaryWithDictionary:userInfo];
if(isClicked) {
remoteNotification[@"clicked"] = @YES;
remoteNotification[@"background"] = @YES;
}
[[XGPush defaultManager] reportXGNotificationInfo:remoteNotification];
[XGPushManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];

[[XGPush defaultManager] reportXGNotificationInfo:userInfo];
[XGPushManager didReceiveRemoteMessage:userInfo fetchCompletionHandler:completionHandler];
}

// iOS 10 新增 API
// iOS 10 会走新 API, iOS 10 以前会走到老 API
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
// App 用户点击通知
// App 用户选择通知中的行为
// App 用户在通知中心清除消息
// 无论本地推送还是远程推送都会走这个回调
- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
NSLog(@"[XGPush] click notification");
if ([response.actionIdentifier isEqualToString:@"xgaction001"]) {
NSLog(@"click from Action1");
} else if ([response.actionIdentifier isEqualToString:@"xgaction002"]) {
NSLog(@"click from Action2");
}

[[XGPush defaultManager] reportXGNotificationResponse:response];

completionHandler();
}

// App 在前台弹通知需要调用这个接口
- (void)xgPushUserNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
[[XGPush defaultManager] reportXGNotificationInfo:notification.request.content.userInfo];
completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionSound | UNNotificationPresentationOptionAlert);
}
#endif


@end
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const EventMapping = Platform.select({
ios: {
register: 'remoteNotificationsRegistered',
notification: 'remoteNotificationReceived',
message: 'remoteMessageReceived',
localNotification: 'localNotificationReceived',
},
});
Expand Down Expand Up @@ -118,7 +119,7 @@ class XGPush {
static addEventListener(eventType, callback) {
let event = EventMapping[eventType];
if (!event) {
console.warn('XGPush only supports `notification`, `register` and `localNotification` events');
console.warn('XGPush only supports `notification`, `register`, `message` ,and `localNotification` events');
return;
}
let listener = XGNativeEventEmitter.addListener(event, (data) => {
Expand All @@ -133,7 +134,7 @@ class XGPush {

static removeEventListener(eventType, callback) {
if (!EventMapping[eventType]) {
console.warn('XGPush only supports `notification`, `register` and `localNotification` events');
console.warn('XGPush only supports `notification`, `register`, `message` and `localNotification` events');
return;
}
let listener = _handlers.get(callback);
Expand Down
2 changes: 2 additions & 0 deletions ios/XGPush/XGPushManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification fetchCompletionHandler:(RCTRemoteNotificationCallback)completionHandler;
+ (void)didReceiveRemoteMessage:(NSDictionary *)notification;
+ (void)didReceiveRemoteMessage:(NSDictionary *)notification fetchCompletionHandler:(RCTRemoteNotificationCallback)completionHandler;
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification;
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
#endif
Expand Down
Loading