简体   繁体   English

科尔多瓦的Windows Phone问题8

[英]Cordova problems with windows phone 8

I am having 2 issues that I can't seem to find a working solution for while using cordova in visual studio 2013. In the config.xml I specified that the orientation should be in portrait mode with this code: 我有两个问题似乎无法找到在visual studio 2013中使用cordova时的工作解决方案。在config.xml中,我指定了方向应该是纵向模式,使用以下代码:

<preference name="Orientation" value="portrait" />

When I run the app on android it obeys this preference just fine and the app does not rotate nor use landscape mode. 当我在Android上运行应用程序时,它服从这个偏好就好了,应用程序不旋转也不使用横向模式。 However on windows phone 8 it still rotates to landscape mode ignoring the setting. 然而,在Windows Phone 8上,它仍然会旋转到横向模式而忽略该设置。

The other issue is that I can't get navigation to work correctly under windows phone 8. My javascript file has this code: 另一个问题是我无法让导航在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();
    };

})();

Again it runs perfectly on Android, however on windows phone 8 the backbutton event does not seem to be called at all. 它再次在Android上完美运行,但是在Windows Phone 8上,后退按钮事件似乎根本没有被调用。 Nothing I put in the function seems to run. 我放在函数中的任何东西似乎都没有运行。 So it seems to be ignoring the listener or not using it. 所以它似乎忽略了听众或不使用它。

Any ideas on how to get this code working correctly for windows phone 8 using cordova? 有关如何使用cordova使Windows Phone 8正常工作的任何想法?

On the orientation issue: it appears that Cordova is dropping the config.xml orientation setting when it creates the Visual Studio project. 在方向问题上:看起来Cordova在创建Visual Studio项目时正在删除config.xml方向设置。 In the package.phone.appxmanifest file (for WP 8.1) you want this inside the <Application> section: 在package.phone.appxmanifest文件(对于WP 8.1)中,您希望在<Application>部分中使用它:

<m3:InitialRotationPreference>
    <m3:Rotation Preference="portrait" />
</m3:InitialRotationPreference>

and in package.windows80.appxmanifest it would be this: 并在package.windows80.appxmanifest中它将是这样的:

<InitialRotationPreference>
    <Rotation Preference="portrait" />
</InitialRotationPreference>

You can also set it programmatically when you initialize your app, and this is the way I do it since then I don't have to go and edit the appxmanifest whenever I remove/add the Windows platform. 您也可以在初始化应用程序时以编程方式设置它,这就是我这样做的方式,从那时起我不必去除/添加Windows平台时编辑appxmanifest。

Windows 8.1 (Javascript): Windows 8.1(Javascript):

if (typeof MSApp !== "undefined") {
    Windows.Graphics.Display.DisplayInformation.autoRotationPreferences =
        Windows.Graphics.Display.DisplayOrientations.portrait;
}

Windows Phone 8 (C#): Windows Phone 8(C#):

Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences = 
    Windows.Graphics.Display.DisplayOrientations.Portrait;

I have found a way to get the back button to work with cordova and wp8.1. 我找到了一种让后退按钮与cordova和wp8.1配合使用的方法。 This requires the use of the WinJS framework. 这需要使用WinJS框架。

In the ondeviceready function use this code: 在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);
}

Then make an onBackKeyDown function to handle the call: 然后创建一个onBackKeyDown函数来处理调用:

function onBackKeyDown() {
    // Back key pressed, do something here
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM