当应用程序在后台并点击通知时,Android react-native-push-notification onNotification未被调用?

时间:2018-03-19 02:00:39

标签: android react-native push-notification google-cloud-messaging react-native-push-notification

当我通过node-pushnotification发送GCM通知时,我在调试模式下的android模拟器上收到通知。

当我点击通知(应用程序在后台运行)时,它会打开应用程序,但不会调用onNotification。我已尝试使用popInitialNotification true和false,没有骰子。

我已经设置了一个单独的pushNotification.js文件,该文件包含在index.js中以确保立即设置,然后我的组件通过默认导出消耗:

import PushNotification from 'react-native-push-notification';

let queued = [];
let config = null;

const queue = (fn) => (...args) => {
  if (!config) {
    queued.push([fn, args])
  }
  else {
    fn(...args);
  }
};

const releaseQueue = () => {
  queued.forEach(queueItem => queueItem[0](...queueItem[1]));
  queued = [];
};

PushNotification.configure({
  onNotification: queue((notification) => {
    config.onNotification(notification)
  }),
  onRegister: queue((...args) => {
    config.onRegister(...args)
  }),
  senderID: 'mySenderId',
  popInitialNotification: true
});

export default (c) => {
  config = c;
  releaseQueue()
};

我已经浏览了与此问题相关的反应推送通知的每个问题的每一个主题。我甚至尝试设置这样的意图过滤器,这样我可能至少可以在我的初始道具中使用推送信息。没有骰子:

    <intent-filter>
      <action android:name="OPEN_MAIN_ACTIVITY" />
      <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>

@Override
protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName()) {
        private JSONObject getPushData(String dataString) {
            try {
                return new JSONObject(dataString);
            } catch (Exception e) {
                return null;
            }
        }

        @Override
        protected Bundle getLaunchOptions() {
            Intent mainIntent = getIntent();
            String dataValue = "";
            Bundle initialProps = new Bundle();
            if (mainIntent != null) {
                Bundle bundle = mainIntent.getExtras();

                if (bundle != null) {
                    JSONObject data = getPushData(bundle.getString("data"));
                    if (data != null) {
                        try {
                            dataValue = data.toString();
                        } catch (Exception e) {
                            // no-op
                        }
                    } else {
                    }
                }
            }
            initialProps.putString("pushData", dataValue); // Read this inside your Root component in React native
            return initialProps;
        }
    };
}

让疯狂的事情变得多么困难。

我的服务器端代码:

const PushNotifications = new require('node-pushnotifications');

const push = new PushNotifications({
  gcm: {
    id: 'my id'
  }
})

  await push.send([token], {
    title: 'My Title',
    body: 'body',
    topic: 'com.myapp',
    custom: {
      myCustomThing: 'myCustomThing
    },
    clickAction: "OPEN_MAIN_ACTIVITY",
  });

1 个答案:

答案 0 :(得分:0)

也许您需要将此行添加到library(tidyverse) TRIPS2_fin %>% filter_at(vars(2,3,4), any_vars(str_detect(., pattern="1|2")))

androidManifest