Я изо всех сил пытаюсь выяснить, почему мое приложение для iOS не может регистрировать щелчки на push-уведомлениях, когда приложение закрыто или завершено.Он прекрасно работает в режиме переднего плана и в фоновом режиме, пока приложение не убито.
Когда приложение "мертво", обратный вызов onNotificationOpen
никогда не запускается, поэтому я не могу направитьПользователь в нужное место в приложении.
Может ли кто-нибудь указать на мои ошибки или предоставить мне рабочий пример?Документация для cordova-plugin-firebase очень минимальна для push-уведомлений.
app.component.ts
this.platform.ready().then(() => {
if (this.platform.is('cordova')) {
this.pushProvider.init();
this.platform.resume.subscribe(() => {
this.pushProvider.init();
});
}
});
push.provider.ts
import { Injectable } from '@angular/core';
import { Firebase } from '@ionic-native/firebase';
import { Platform } from 'ionic-angular';
@Injectable()
export class PushNotificationsProvider {
constructor (private firebase: Firebase, private platform: Platform) {
}
init () {
if (!this.platform.is('cordova')) {
return;
}
if (this.platform.is('ios')) {
this.firebase.grantPermission().then(() => {
this.initListeners();
});
} else if (this.platform.is('android')) {
this.firebase.hasPermission().then(data => {
if (data && data.isEnabled) {
this.initListeners();
}
});
}
}
initListeners () {
this.firebase.onNotificationOpen().subscribe((notification: any) => {
this.handleNotification(notification);
});
}
handleNotification (notification) {
if (!notification) {
return;
}
if (notification.tap) {
this.backgroundNotification(notification);
} else {
this.foregroundNotification(notification);
}
}
backgroundNotification (notification) {
const message = (notification.aps || {}).alert;
alert('*** FMC: opened in background: ' + message);
}
foregroundNotification (notification) {
const message = (notification.aps || {}).alert;
alert('*** FMC: opened in foreground: ' + message);
}
}
package.json
{
"ionic-angular": "3.9.2",
"cordova-plugin-firebase": "^1.0.2"
"@ionic-native/firebase": "^4.7.0"
}