Android реакции-родной-push-уведомления onNotification не вызывается, когда приложение находится в фоновом режиме и уведомление нажал?
Когда я отправляю уведомление GCM через узел-pushnotification, я получаю уведомление на моем симуляторе Android в режиме отладки.
Когда я нажимаю на уведомление (приложение работает в фоновом режиме), оно открывает приложение, но не вызывает onNotification. Я пробовал с обоими popInitialNotification истина и ложь, без кости.
Я создал отдельный 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()
};
Я рассмотрел каждую ветку каждой проблемы по реакции на нажатие, касающейся этой проблемы. Я даже попытался настроить фильтр намерений, например, так, чтобы, возможно, я мог, по крайней мере, иметь push-информацию в моем начальном реквизите. Нет кости:
<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",
});
0 ответов
Возможно, вам нужно добавить эту строку в androidManifest
:
android:launchMode="singleInstance"