Tôi đang phát triển Windows phone 8 PhoneGap app. Sử dụng navigator.app.exitApp() Tôi đang bỏ ứng dụng từ màn hình chính trong điện thoại Windows 7. Nhưng khi tôi cố gắng tương tự trong Windows phone 8, tôi nhận được lỗi Unable to get property 'exitApp' of undefined or null reference
. Tôi muốn biết tại sao nó không được xác định trong Windows phone 8 và không có trong điện thoại Window PhoneGap 7 ứng dụng. Ngoài ra, tôi muốn biết, có cách nào để thoát khỏi ứng dụng lập trình trong Windows Phone 8 ứng dụng PhoneGap không ?.navigator.app.exitApp() không hoạt động
Trả lời
tương tự câu hỏi ở đây: https://groups.google.com/forum/#!msg/phonegap/9v2kOwXj6sQ/O8SVpd-qjicJ
Nhưng nó về cơ bản nói rằng windows phone 8 ứng dụng không nên thoát chương trình khác.
Navigator.app.exit()
sẽ không thoát khỏi ứng dụng, nó sẽ làm hỏng ứng dụng.
Trong Windows Phone 8, nó được xử lý để nó sẽ chỉ ném một ngoại lệ.
Bạn sẽ phải viết mã dưới đây trong trường hợp page_BackKeyPress trong CordovaView.xaml.cs
Application.Current.Terminate();
Nó sẽ thoát ứng dụng của bạn trên nhấn backbutton phần cứng.
Navigator.app.exit() không được định nghĩa trong WP8 trên Cordova 3+ –
Bạn có thể tạo một plugin đơn giản. Thêm ExitApp.css tập tin vào thư mục WP8/nền tảng của bạn/Plugins với:
using System.Windows;
namespace WPCordovaClassLib.Cordova.Commands
{
class ExitApp : BaseCommand
{
public void execute(string options)
{
Application.Current.Terminate();
}
}
}
chỉnh sửa nền tảng của bạn/WP8/config.xml và thêm vào các thẻ phụ tùng:
<feature name="ExitApp">
<param name="wp-package" value="ExitApp" />
</feature>`
sau đó từ bạn gọi javascript :
cordova.exec(null, null, "ExitApp", "execute", []);
Bạn có thể sử dụng nó kết hợp với sự kiện backbutton để đóng ứng dụng khi người dùng nhấp vào backbutton trong trang chính:
function goBack(e){
if(isInMyMainPage()) cordova.exec(null, null, "ExitApp", "execute", []);
}
document.addEventListener("backbutton", goBack, false)
tại sao downvote câu trả lời này? Tôi đang sử dụng nó trong sản xuất. – TlmaK0
Hữu ích !! Làm việc của nó .... Cảm ơn bạn !!! – BlackPOP
Cảm ơn bạn ... Hoạt động của nó – ConnectingCode
Câu hỏi tương tự ở đây: How to exit an application in window phone 8 with phonegap 2.3 bao gồm bản sửa lỗi không yêu cầu bất kỳ sự tấn công gốc nào.
Trong phiên bản 3.6.3, navigator.app.exitApp() không hoạt động.
Đây là nơi nó được gọi trong 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);
}
}
}
navigator.app.exitApp(); đã có sẵn trong các dự án Apache Cordova WP8 từ 3.4.0
<div onclick="navigator.app.exitApp()">Exodus</div>
tôi phát triển ứng dụng nhỏ cho Windows Phone 8.1 và mã dưới đây làm việc cho tôi:
window.close();
Tuyệt vời! Nó hoạt động cho tôi trên Windows 10 Apps – SergiP
này là không đúng, bạn có thể làm điều đó tạo ra một pluging đơn giản, nhìn vào answerd của tôi – TlmaK0