Skip to content
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
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -42,9 +42,9 @@ c.在`AppDelegate.m`中加入
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...

[RCTJPush application:application didFinishLaunchingWithOptions:launchOptions];

...
}

Expand Down Expand Up @@ -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=> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -275,4 +286,4 @@ private boolean _isApplicationRunning(Context context) {
return false;
}
}
}
}
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -166,5 +174,3 @@ function checkListenerType(type) {
'JPushNotification only supports `JpushEventReceiveMessage` ,`JpushEventOpenMessage`, `JpushEventReceiveCustomMessage`, events'
);
}