【发布时间】:2017-04-08 16:00:55
【问题描述】:
当我在主页上使用我的 Cordova 应用程序时,我需要向用户显示消息,询问他是否真的要退出应用程序。
如果用户选择“是”,我需要退出应用程序。
为此,我使用以下代码:
document.addEventListener('backbutton', function() {
$rootScope.back();
$rootScope.$apply();
}, false);
$rootScope.back = function(execute) {
var path = $location.$$path;
if (path !== '/') {
$location.path(path.split('/').slice(0, -1).join('/'));
} else {
$rootScope.exitApp();
}
}.bind(this);
$rootScope.exitApp = function() {
$rootScope.$emit('showPopover', {
message: $rootScope.LABELS.QUIT_APP,
confirmCallback: function() {
if (typeof navigator.app !== 'undefined') {
navigator.app.exitApp();
}
},
cancelCallback: doNothing
});
};
它适用于 android 和 iOS,但不适用于 Windows 10 应用程序。
在 W10 中,navigator.app 未定义。
我读到我应该暂停应用程序而不是退出它,所以我尝试了这个 windows quirkswritten in cordova doc (https://cordova.apache.org/docs/en/latest/cordova/events/events.html#backbutton) :
$rootScope.exitApp = function() {
$rootScope.$emit('showPopover', {
message: $rootScope.LABELS.QUIT_APP,
confirmCallback: function() {
if (typeof navigator.app !== 'undefined') {
navigator.app.exitApp();
}
else if (platformUtils.isWindows()) {
throw new Error('Exit'); // This will suspend the app
}
},
cancelCallback: doNothing
});
};
throw new Error('Exit') 被调用并在日志中显示错误,但应用并未暂停。
也许是因为我在一个有角度的应用程序中?
有人有想法吗?
【问题讨论】:
标签: angularjs windows cordova uwp windows-10-universal