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' ); } - -