2016-12-17 10 views
0

私は自分のアプリでIonicを使用しましたが、物理バックボタンを押すと、最後の状態に戻るのではなく、アプリケーションを終了する必要があります。

私は$ionicPlatform.registerBackButtonActionイベントを聞いて実行しません。

app.js

app.run(function ($rootScope, $cordovaToast, $ionicPlatform, $state, $cordovaKeyboard) { 
    var deregister; 
    $ionicPlatform.ready(function() { 

if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { 
    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    cordova.plugins.Keyboard.disableScroll(true); 

} 
if (window.StatusBar) { 
    StatusBar.styleDefault(); 
} 
$ionicPlatform.registerBackButtonAction(function (event) { 
    event.preventDefault(); 
    console.info('天啦噜,你终于执行了') 
    if ($state.current.name == "tab.discover") { 
    console.info('哈哈,要退出了') 
    navigator.app.exitApp(); 
    } 
    else { 
    console.info('哈哈,要返回了') 
    navigator.app.backHistory(); 
    } 
}, 101); 

})。そのそれは、より正確にするために代わり==の3 ===を使用すべきかどうかを確認するには

+0

「ionic serve」ではこれが機能しますか?つまり、問題は本当にアンドロイド特有ですか? –

答えて

0

それが戻ってページを起こっているので、問題は$state.current.nameと最も可能性があり、console.log($state.current.name)。そうでない場合はregisterBackButtonActionの101から100を変更してみてください。

+0

ok.t​​hank、私はそれを拒否しました –

+1

私の答えが正しい場合は、それを受け入れられた回答としてマークしてください。 – Olli

関連する問題