2013-07-30 3 views
6

Windows Phone 8 PhoneGap 앱을 개발 중입니다. navigator.app.exitApp() 사용 Windows Phone 7의 홈 화면에서 앱을 종료합니다.하지만 Windows Phone 8에서 동일한 시도를하면 Unable to get property 'exitApp' of undefined or null reference 오류가 발생합니다. Windows Phone 7 PhoneGap 앱이 아닌 Windows Phone 8에서 정의되지 않은 이유를 알고 싶습니다. 또한, 알고 싶습니다, Windows 전화 8 PhoneGap 응용 프로그램에서 프로그래밍 방식으로 응용 프로그램을 종료하는 방법이 있습니까?. 여기navigator.app.exitApp()가 작동하지 않습니다.

답변

0

Navigator.app.exit() 응용 프로그램을 종료하지 않으면 응용 프로그램이 중단됩니다.

Windows Phone 8에서는 예외가 발생하므로 처리됩니다.

당신은 하드웨어 BACK 버튼을 눌러에서 응용 프로그램을 종료합니다

Application.Current.Terminate(); 
CordovaView.xaml.cs

에 page_BackKeyPress 이벤트에 아래의 코드를 작성해야합니다.

+0

Navigator.app.exit() WP8 Cordova 3+ –

9

간단한 플러그인을 만들 수 있습니다.

using System.Windows; 

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

편집하여 플랫폼/WP8/config.xml 파일을 위젯 태그에 추가 : 당신의 플랫폼/WP8/플러그인 폴더에 파일 ExitApp.css 추가에서 다음

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

자바 스크립트 호출

: 사용자가 메인 페이지에서 BACK 버튼을 클릭 할 때

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

당신은 응용 프로그램을 닫습니다 BACK 버튼 이벤트와 함께 사용할 수 있습니다

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

에 정의되지 않은 이유는 무엇입니까? 프로덕션에서 사용하고 있습니다. – TlmaK0

+0

유용 !! 그것의 일 .... 고맙습니다 !!! – BlackPOP

+0

고마워요 ... 그 일이 – ConnectingCode

0

버전 3.6.3에서 navigator.app.exitApp()가 작동합니다. 여기

은)는 (CordovaView.cs

void CordovaBrowser_ScriptNotify(object sender, NotifyEventArgs e) 
{ 
    string commandStr = e.Value; 

    string commandName = commandStr.Split('/').FirstOrDefault(); 

    if (browserDecorators.ContainsKey(commandName)) 
    { 
     browserDecorators[commandName].HandleCommand(commandStr); 
     return; 
    } 

    CordovaCommandCall commandCallParams = CordovaCommandCall.Parse(commandStr); 

    if (commandCallParams == null) 
    { 
     // ERROR 
     Debug.WriteLine("ScriptNotify :: " + commandStr); 
    } 
    else if (commandCallParams.Service == "CoreEvents") 
    { 
     switch (commandCallParams.Action.ToLower()) 
     { 
      case "overridebackbutton": 
       string arg0 = JsonHelper.Deserialize<string[]>(commandCallParams.Args)[0]; 
       this.OverrideBackButton = (arg0 != null && arg0.Length > 0 && arg0.ToLower() == "true"); 
       break; 
      case "__exitapp": 
       Debug.WriteLine("Received exitApp command from javascript, app will now exit."); 
       CordovaBrowser.InvokeScript("eval", new string[] { "cordova.fireDocumentEvent('pause');" }); 
       CordovaBrowser.InvokeScript("eval", new string[] { "setTimeout(function(){ cordova.fireDocumentEvent('exit'); cordova.exec(null,null,'CoreEvents','__finalexit',[]); },0);" }); 
       break; 
      case "__finalexit": 
       IsExiting = true; 
       // hide the browser to prevent white flashes, since about:blank seems to always be white 
       CordovaBrowser.Opacity = 0d; 
       CordovaBrowser.Navigate(new Uri("about:blank", UriKind.Absolute)); 
       break; 
     } 
    } 
    else 
    { 
     if (configHandler.IsPluginAllowed(commandCallParams.Service)) 
     { 
      commandCallParams.Namespace = configHandler.GetNamespaceForCommand(commandCallParams.Service); 
      nativeExecution.ProcessCommand(commandCallParams); 
     } 
     else 
     { 
      Debug.WriteLine("Error::Plugin not allowed in config.xml. " + commandCallParams.Service); 
     } 
    } 
} 
0

navigator.app.exitApp에서 호출되는 경우; 나는 윈도우 폰 8.1 아래의 코드에 대한 작은 응용 프로그램을 개발 3.4.0

<div onclick="navigator.app.exitApp()">Exodus</div> 
1

이후 아파치 코르도바 WP8 프로젝트에 사용할 수있다하는 것은 나를 위해 작동 :

window.close(); 
+0

멋지다! Windows 10 Apps에서 작동합니다. – SergiP

관련 문제