From 737b49a44a3ae4e289bce846dd33fe83e7c7d886 Mon Sep 17 00:00:00 2001 From: DQP Date: Fri, 15 Jul 2016 11:38:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=20getHoldMessages?= =?UTF-8?q?=E6=96=B9=E6=B3=95,=E8=A7=A3=E5=86=B3=E5=BD=93APP=E8=BF=9B?= =?UTF-8?q?=E5=85=A5=E5=90=8E=E5=8F=B0,=E7=82=B9=E5=87=BB=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E6=B6=88=E6=81=AF=20=E4=B8=8D=E6=89=A7=E8=A1=8ConOpen?= =?UTF-8?q?Message=20=E7=9A=84=E7=9B=91=E5=90=AC=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 +++++++++++++---- .../reactnative/modules/jpush/JPushModule.java | 13 ++++++++++++- index.js | 10 ++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7af4e74..b7f3919 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ npm install react-native-jpush --save rnpm link react-native-jpush ``` -#### Note: +#### Note: * rnpm requires node version 4.1 or higher * Android SDK Build-tools 23.0.2 or higher @@ -42,9 +42,9 @@ c.在`AppDelegate.m`中加入 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... - + [RCTJPush application:application didFinishLaunchingWithOptions:launchOptions]; - + ... } @@ -91,7 +91,16 @@ componentDidMount() { this.pushlisteners = [ JPush.addEventListener(JpushEventReceiveMessage, this.onReceiveMessage.bind(this)), JPush.addEventListener(JpushEventOpenMessage, this.onOpenMessage.bind(this)), - ] + ]; + AppState.addEventListener('change', (appState)=>{ + if(appState == 'active') { + JPush.getHoldMessages((message)=>{ + if(message){ + this.onOpenMessage(message); + } + }); + } + }); } componentWillUnmount() { this.pushlisteners.forEach(listener=> { diff --git a/android/src/main/java/cn/reactnative/modules/jpush/JPushModule.java b/android/src/main/java/cn/reactnative/modules/jpush/JPushModule.java index adfa154..14e6b28 100644 --- a/android/src/main/java/cn/reactnative/modules/jpush/JPushModule.java +++ b/android/src/main/java/cn/reactnative/modules/jpush/JPushModule.java @@ -148,6 +148,17 @@ public void stopPush(){ JPushInterface.stopPush(getReactApplicationContext()); } + @ReactMethod + public void getMyHoldMessage(Callback success_callback) { + if(JPushModule.holdMessage != null){ + String str = new String(JPushModule.holdMessage); + JPushModule.holdMessage = null; + success_callback.invoke(str); + }else { + success_callback.invoke(new String()); + } + } + @ReactMethod public void resumePush(){ JPushInterface.resumePush(getReactApplicationContext()); @@ -275,4 +286,4 @@ private boolean _isApplicationRunning(Context context) { return false; } } -} \ No newline at end of file +} diff --git a/index.js b/index.js index aa06ff5..20f5dbe 100644 --- a/index.js +++ b/index.js @@ -51,6 +51,14 @@ export default class JPushNotification { nativeModule.setTags(tags, alias) } + static getHoldMessages(callback){ + nativeModule.getMyHoldMessage((data)=>{ + if(data){ + callback(new JPushNotification(data)); + } + }); + } + static getRegistrationID(){ return new Promise(resolve=>{ nativeModule.getRegistrationID(resolve) @@ -166,5 +174,3 @@ function checkListenerType(type) { 'JPushNotification only supports `JpushEventReceiveMessage` ,`JpushEventOpenMessage`, `JpushEventReceiveCustomMessage`, events' ); } - -