Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI 在前端的时候 打开推送消息 才会执行监听方法 #29

Open
Ping5841 opened this issue Jul 14, 2016 · 3 comments
Open

UI 在前端的时候 打开推送消息 才会执行监听方法 #29

Ping5841 opened this issue Jul 14, 2016 · 3 comments

Comments

@Ping5841
Copy link

UI 在前端的时候 打开推送消息 才会执行监听方法?
UI在后端 点击推送消息 只是打开APP 不执行监听方法 ??
有解决办法吗

@Ping5841
Copy link
Author

在源码加了个方法
JPushModule.java

@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());
      }
    }

index.js

static getHoldMessages(callback){
        nativeModule.getMyHoldMessage((data)=>{
            if(data){
                callback(new JPushNotification(data));
            }
        });
    }

监听方法加了这个
app从后端跳转到前端监听

componentDidMount() {
    JPush.requestPermissions()
    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)=>{
                         // console.log(message);
                         if(message){
                             this.onOpenMessage(message);
                         }
                     });
                 }
           });
}

暂时解决了问题 ,不知道有什么更好的方法吗??

@tdzl2003
Copy link
Member

tdzl2003 commented Oct 6, 2016

这个解决方法是正确的,可否提交一个PR给我们呢

@Ping5841
Copy link
Author

Ping5841 commented Nov 2, 2016

@tdzl2003 之前就提交过了PR了,合并一下吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants