navigator.app.exitApp()无法正常工作

编程入门 行业动态 更新时间:2024-10-13 08:20:20
本文介绍了navigator.app.exitApp()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发Windows Phone 8 PhoneGap应用程式。使用navigator.app.exitApp()我在Windows Phone 7的主屏幕上退出应用程序。但是当我在Windows Phone 8尝试相同的,我得到错误无法获取属性'exitApp' of undefined或null引用。我想知道为什么它是未定义在Windows Phone 8,而不是在Windows Phone 7 PhoneGap应用程序。此外,我想知道,有什么办法在Windows Phone 8 PhoneGap应用程序中以编程方式退出应用程序。

I am developing Windows phone 8 PhoneGap app. Using navigator.app.exitApp() I am quiting the app from home screen in Windows phone 7. But when I tried the same in Windows phone 8, I am getting the error Unable to get property 'exitApp' of undefined or null reference. I would like to know why it is undefined in Windows phone 8 and not in Window phone 7 PhoneGap app. Also, I would like to know, is there any way to quit the app programmatically in Windows phone 8 PhoneGap app?.

推荐答案

您可以创建一个简单的插件。使用System.Windows将文件ExitApp.css添加到您的平台/ wp8 / Plugins文件夹中:

You can create a simple plugin. Add file ExitApp.css to your platforms/wp8/Plugins folder with:

using System.Windows; namespace WPCordovaClassLib.Cordova.Commands { class ExitApp : BaseCommand { public void execute(string options) { Application.Current.Terminate(); } } }

编辑您的平台/ wp8 / config.xml并添加到窗口小部件标记:

edit your platforms/wp8/config.xml and add to the widget tag:

<feature name="ExitApp"> <param name="wp-package" value="ExitApp" /> </feature>`

然后从javascript javascript call:

then from you javascript call:

cordova.exec(null, null, "ExitApp", "execute", []);

您可以结合使用它与backbutton事件关闭应用程序,当用户点击backbutton主页:

You can use it in combination with backbutton event to close the app when the user clicks on backbutton in the main page:

function goBack(e){ if(isInMyMainPage()) cordova.exec(null, null, "ExitApp", "execute", []); } document.addEventListener("backbutton", goBack, false)

更多推荐

navigator.app.exitApp()无法正常工作

本文发布于:2023-11-27 19:57:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639393.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   工作   navigator   app   exitApp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!