如何在离子2中将应用程序从背景应用到前景?
问题描述:
当事件发生像通知到达时,是否有任何可能的方式将应用程序从background
模式带入?如WhatsApp和Skype,当语音通话或视频通话到达时,它将进入前台。如何在离子2中将应用程序从背景应用到前景?
更新:
public subscribeToPushNotificationEvents(): void {
// Handle token refresh
this.firebase.onTokenRefresh().subscribe(
token => {
//console.log(`The new token is ${token}`);
this.saveToken(token);
},
error => {
console.error('Error refreshing token', error);
});
// Handle incoming notifications
this.firebase.onNotificationOpen().subscribe(
(notification: NotificationModel) => {
this.backgroundMode.moveToForeground();
let notificationAlert = this.alertCtrl.create({
title: notification.title,
message: notification.body,
buttons: ['Ok']
});
notificationAlert.present();
}
我已经更新,但该应用程序不会前景和应用程序有时会崩溃。崩溃与'this.backgroundMode.moveToForeground();'代码无关。 – RSA