componentDidMount() {
PushNotificationIOS.cancelAllLocalNotifications();
PushNotificationIOS.addEventListener('localNotification', this._onNotification);
PushNotificationIOS.checkPermissions(async res => {
var localPushChecker = await AsyncStorage.getItem("localPushChecker");
if (localPushChecker === null) {
await AsyncStorage.setItem("localPushChecker", "1");
if (res.alert !== 1) {
PushNotificationIOS.requestPermissions();
}
}
else {
this.scheduleNotification();
}
});
}
async _onNotification(notification) {
console.log(AppState.currentState);
if (AppState.currentState === "background") {
try {
var query = "http://content_to_fetch";
var contents = (await axios.get(query)).data;
var section = Categories.contentSection[contents[0].Content_Mark.toString()];
var message = section + ":\n" + contents[0].Content_Title;
var uri = "http://content_to_fetch";
Actions.web({
title: section,
uri: uri
});
} catch (err) {
console.log(err);
}
}
}
async scheduleNotification() {
try {
var query = "http://content_to_fetch";
var contents = (await axios.get(query)).data;
var section = Categories.contentSection[contents[0].Content_Mark.toString()];
var message = section + ":" + contents[0].Content_Title;
var fireDate = new Date(Date.now() + (15 * 1000));
PushNotificationIOS.scheduleLocalNotification({
fireDate: fireDate,
alertTitle: "Myapp",
alertBody: message,
alertAction: "view",
repeatInterval: "minute"
});
} catch (err) {
console.log(err);
}
}
Я пишу мобильное приложение.Я пытаюсь обновить push-уведомление, когда мы обновляем ссылку в серверной части.Проблема в том, что когда мы меняем ссылку, мы хотим вставить ее в бэкэнд.Приложение все еще пытается нажать на предыдущую ссылку.
Я пытался исправить это с помощью функции setinterval (), как показано ниже, чтобы обновлять его каждые 100 секунд:
componentDidMount() {
........
else {
setInterval(() => {
console.log('testing');
this.scheduleNotification();
}, 100000);
}
});
}
Но я заметил, что push-уведомление будет обновляться только тогда, когда приложениеактивенКогда приложение находится в фоновом режиме, push-уведомление не будет обновляться, поскольку console.log не выполняется.Есть ли способ обновить push-уведомление, когда приложение находится в фоновом режиме?Заранее спасибо.