如何在离子2中将应用程序从背景应用到前景?

问题描述:

当事件发生像通知到达时,是否有任何可能的方式将应用程序从background模式带入​​?如WhatsAppSkype,当语音通话或视频通话到达时,它将进入前台。如何在离子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(); 
} 

据我所知,你唯一的选择是这个插件:http://ionicframework.com/docs/native/background-mode/

+0

我已经更新,但该应用程序不会前景和应用程序有时会崩溃。崩溃与'this.backgroundMode.moveToForeground();'代码无关。 – RSA