2016-10-12 135 views
0

我想知道如何確定何時使用硬件返回按鈕退出應用程序,並最終清除localStorage數據。如何使用ionic2退出應用程序時清除localStorage

我需要這三個主要的原因:1。 詢問用戶,如果他/她真的想退出應用程序 2.清除緩存數據 3.強制用戶總是隨時登錄該應用程序啓動 - 因爲這是金融應用程序。

謝謝

回答

0

用於確定何時退出應用程序。您必須參考this link

使用registerBackButtonAction()方法來處理後退硬件。

例如:在app.ts文件

initializeApp() { 
this.platform.ready().then(() => { 
    // Okay, so the platform is ready and our plugins are available. 
    // Here you can do any higher level native things you might need. 
    this.platform.registerBackButtonAction(() =>{ 
    // 1. Ask the user if he/she really wants to exit the application 
    //2. Clear cached data 
    //3. Force the user to always login anytime the application is started 
    return; 
    }); 
    StatusBar.styleDefault(); 
}); 
} 

歡呼!

+0

感謝您的快速響應。 – Aweda

相關問題