windows phone 8 的 Cordova 问题
Cordova problems with windows phone 8
我在 visual studio 2013 年使用 cordova 时遇到 2 个问题,我似乎无法找到有效的解决方案。在 config.xml 中,我指定方向应为纵向模式使用此代码:
<preference name="Orientation" value="portrait" />
当我 运行 android 上的应用程序时,它很好地遵守此首选项,并且应用程序不会旋转,也不会使用横向模式。但是在 windows phone 8 上它仍然旋转到横向模式而忽略设置。
另一个问题是我无法让导航在 windows 下正常工作 phone 8. 我的 javascript 文件有这个代码:
(function () {
"use strict";
document.addEventListener('deviceready', onDeviceReady.bind(this), false);
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener('pause', onPause.bind(this), false);
document.addEventListener('resume', onResume.bind(this), false);
document.addEventListener("backbutton", onBackKeyDown, false);
};
function onPause() {
// TODO: This application has been suspended. Save application state here.
};
function onResume() {
// TODO: This application has been reactivated. Restore application state here.
};
function onBackKeyDown() {
history.go(-1);
navigator.app.backHistory();
};
})();
再次 运行 在 Android 上完美,但是在 windows phone 8 上似乎根本没有调用后退按钮事件。我放入函数中的任何内容似乎都 运行。所以它似乎忽略了监听器或者没有使用它。
关于如何使用 cordova 使此代码在 windows phone 8 上正常工作的任何想法?
关于方向问题:Cordova 在创建 Visual Studio 项目时似乎放弃了 config.xml 方向设置。在 package.phone.appxmanifest 文件(对于 WP 8.1)中,您希望在 部分中这样做:
<m3:InitialRotationPreference>
<m3:Rotation Preference="portrait" />
</m3:InitialRotationPreference>
在 package.windows80.appxmanifest 中是这样的:
<InitialRotationPreference>
<Rotation Preference="portrait" />
</InitialRotationPreference>
您还可以在初始化您的应用程序时以编程方式设置它,从那时起我就是这样做的,我不必在 remove/add [=29= 时去编辑 appxmanifest ] 平台.
Windows 8.1 (Javascript):
if (typeof MSApp !== "undefined") {
Windows.Graphics.Display.DisplayInformation.autoRotationPreferences =
Windows.Graphics.Display.DisplayOrientations.portrait;
}
Windows Phone 8 (C#):
Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences =
Windows.Graphics.Display.DisplayOrientations.Portrait;
我找到了一种让后退按钮与 cordova 和 wp8.1 一起工作的方法。这需要使用WinJS框架。
在 ondeviceready 函数中使用此代码:
if (device.platform == "windows") {
// Get the back button working in WP8.1
WinJS.Application.onbackclick = function () {
onBackKeyDown();
return true; // This line is important, without it the app closes.
}
}
else {
document.addEventListener("backbutton", onBackKeyDown, false);
}
然后制作一个onBackKeyDown函数来处理调用:
function onBackKeyDown() {
// Back key pressed, do something here
};
我在 visual studio 2013 年使用 cordova 时遇到 2 个问题,我似乎无法找到有效的解决方案。在 config.xml 中,我指定方向应为纵向模式使用此代码:
<preference name="Orientation" value="portrait" />
当我 运行 android 上的应用程序时,它很好地遵守此首选项,并且应用程序不会旋转,也不会使用横向模式。但是在 windows phone 8 上它仍然旋转到横向模式而忽略设置。
另一个问题是我无法让导航在 windows 下正常工作 phone 8. 我的 javascript 文件有这个代码:
(function () {
"use strict";
document.addEventListener('deviceready', onDeviceReady.bind(this), false);
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener('pause', onPause.bind(this), false);
document.addEventListener('resume', onResume.bind(this), false);
document.addEventListener("backbutton", onBackKeyDown, false);
};
function onPause() {
// TODO: This application has been suspended. Save application state here.
};
function onResume() {
// TODO: This application has been reactivated. Restore application state here.
};
function onBackKeyDown() {
history.go(-1);
navigator.app.backHistory();
};
})();
再次 运行 在 Android 上完美,但是在 windows phone 8 上似乎根本没有调用后退按钮事件。我放入函数中的任何内容似乎都 运行。所以它似乎忽略了监听器或者没有使用它。
关于如何使用 cordova 使此代码在 windows phone 8 上正常工作的任何想法?
关于方向问题:Cordova 在创建 Visual Studio 项目时似乎放弃了 config.xml 方向设置。在 package.phone.appxmanifest 文件(对于 WP 8.1)中,您希望在
<m3:InitialRotationPreference>
<m3:Rotation Preference="portrait" />
</m3:InitialRotationPreference>
在 package.windows80.appxmanifest 中是这样的:
<InitialRotationPreference>
<Rotation Preference="portrait" />
</InitialRotationPreference>
您还可以在初始化您的应用程序时以编程方式设置它,从那时起我就是这样做的,我不必在 remove/add [=29= 时去编辑 appxmanifest ] 平台.
Windows 8.1 (Javascript):
if (typeof MSApp !== "undefined") {
Windows.Graphics.Display.DisplayInformation.autoRotationPreferences =
Windows.Graphics.Display.DisplayOrientations.portrait;
}
Windows Phone 8 (C#):
Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences =
Windows.Graphics.Display.DisplayOrientations.Portrait;
我找到了一种让后退按钮与 cordova 和 wp8.1 一起工作的方法。这需要使用WinJS框架。
在 ondeviceready 函数中使用此代码:
if (device.platform == "windows") {
// Get the back button working in WP8.1
WinJS.Application.onbackclick = function () {
onBackKeyDown();
return true; // This line is important, without it the app closes.
}
}
else {
document.addEventListener("backbutton", onBackKeyDown, false);
}
然后制作一个onBackKeyDown函数来处理调用:
function onBackKeyDown() {
// Back key pressed, do something here
};