navigator.app.exitApp()无法正常工作 [英] navigator.app.exitApp() is not working

查看:960
本文介绍了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()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆