navigator.app.exitApp() is not working

后端 未结 7 1095
予麋鹿
予麋鹿 2021-01-05 14:36

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 ph

7条回答
  •  情书的邮戳
    2021-01-05 15:23

    In version 3.6.3, navigator.app.exitApp() does work.

    Here is where it is called in 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(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);
            }
        }
    }
    

提交回复
热议问题