是否可以从使用cordova的Android应用程序生成ios应用程序?

时间:2016-04-04 13:29:02

标签: android ios cordova

我的问题是,如果我可以使用Cordova获得运行Android应用程序的ios版本?我试过添加这样的平台:

//I add the platform
cordova platform add ios
//I compile the project
cordova build ios

然后我尝试运行它,但它工作得很糟糕,它加载一个空白屏幕,项目说它运行。我认为这是一个配置问题。自动创建的config.xml(ios)如下所示:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.project.appios" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <preference name="AllowInlineMediaPlayback" value="false" />
    <preference name="BackupWebStorage" value="cloud" />
    <preference name="DisallowOverscroll" value="false" />
    <preference name="EnableViewportScale" value="false" />
    <preference name="KeyboardDisplayRequiresUserAction" value="true" />
    <preference name="MediaPlaybackRequiresUserAction" value="false" />
    <preference name="SuppressesIncrementalRendering" value="false" />
    <preference name="SuppressesLongPressGesture" value="false" />
    <preference name="Suppresses3DTouchGesture" value="false" />
    <preference name="GapBetweenPages" value="0" />
    <preference name="PageLength" value="0" />
    <preference name="PaginationBreakingMode" value="page" />
    <preference name="PaginationMode" value="unpaginated" />
    <feature name="LocalStorage">
        <param name="ios-package" value="CDVLocalStorage" />
    </feature>
    <feature name="HandleOpenUrl">
        <param name="ios-package" value="CDVHandleOpenURL" />
        <param name="onload" value="true" />
    </feature>
    <feature name="IntentAndNavigationFilter">
        <param name="ios-package" value="CDVIntentAndNavigationFilter" />
        <param name="onload" value="true" />
    </feature>
    <feature name="GestureHandler">
        <param name="ios-package" value="CDVGestureHandler" />
        <param name="onload" value="true" />
    </feature>
    <feature name="Camera">
        <param name="ios-package" value="CDVCamera" />
    </feature>
    <preference name="CameraUsesGeolocation" value="false" />
    <feature name="File">
        <param name="ios-package" value="CDVFile" />
        <param name="onload" value="true" />
    </feature>
    <feature name="Geolocation">
        <param name="ios-package" value="CDVLocation" />
    </feature>
    <feature name="Media">
        <param name="ios-package" value="CDVSound" />
    </feature>
    <feature name="Capture">
        <param name="ios-package" value="CDVCapture" />
    </feature>
    <feature name="Contacts">
        <param name="ios-package" value="CDVContacts" />
    </feature>
    <feature name="FileTransfer">
        <param name="ios-package" value="CDVFileTransfer" />
    </feature>
    <feature name="InAppBrowser">
        <param name="ios-package" value="CDVInAppBrowser" />
    </feature>
    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="*" />
</widget>

root config.xml如下所示:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.medife.appios" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>*****</name>
    <description>
        ******************
    </description>
    <author email="*******************************">
        *********
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="*" />
    <preference name="SplashScreen" value="screen"/>
    <preference name="SplashScreenDelay" value="5000" />
    <preference name="ShowSplashScreenSpinner" value="false" />
    <preference name="orientation" value="portrait" />
    <platform name="android">
    <!-- you can use any density that exists in the Android project -->
        <splash src="res/screen/android/splash-port-hdpi.png" density="port-hdpi"/>
        <splash src="res/screen/android/splash-port-ldpi.png" density="port-ldpi"/>
        <splash src="res/screen/android/splash-port-mdpi.png" density="port-mdpi"/>
        <splash src="res/screen/android/splash-port-xhdpi.png" density="port-xhdpi"/>
    </platform>
    <platform name="ios">
        <!-- images are determined by width and height. The following are supported -->
        <splash src="res/screen/ios/default-568-iphone.png" width="640" height="1136"/>
        <splash src="res/screen/ios/default-667-iphone.png" width="750" height="1334"/>
        <splash src="res/screen/ios/default-736-iphone.png" width="1242" height="2208"/>
    </platform>
    <icon src="res/logo/logo.png" />
</widget>

我删除了作者,说明和电子邮件......

更新:我注意到,在XCode控制台中,缺少某些插件,因此即时检查有关此问题的其他stackoverflow答案。我认为这是因为该应用程序的后端是使用较旧版本的iOS制作的。

提前致谢!

1 个答案:

答案 0 :(得分:0)

最后我明白了。我发布了答案,所以如果有人遇到同样的问题,它可以提供帮助:

首先是几件事: 1)启动画面插件没有问题,它工作得很好,我只是更新它,它很漂亮。 2)我不得不改变一些jquery,因为它在ios上运行不正常: 我改变了

$(document).ready(function() {
    onDeviceReady();
});

document.addEventListener('deviceready', onDeviceReady, false);

最后,这是我的config.xml(适用于Android和iOS):

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.medife.mobile" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>APP NAME</name>
    <description>
        YOUR DESCRIPTION
    </description>
    <author email="YOURMAIL" href="">
        YOUR NAME
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="*" />
    <allow-intent href="*" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="7500" />
    <preference name="ShowSplashScreenSpinner" value="false" />
    <preference name="orientation" value="portrait" />
    <preference name="AutoHideSplashScreen" value="false" />
    <platform name="android">
        <splash density="port-hdpi" src="res/screen/android/splash-port-hdpi.png" />
        <splash density="port-ldpi" src="res/screen/android/splash-port-ldpi.png" />
        <splash density="port-mdpi" src="res/screen/android/splash-port-mdpi.png" />
        <splash density="port-xhdpi" src="res/screen/android/splash-port-xhdpi.png" />
    </platform>
    <platform name="ios">
        <splash src="res/screen/ios/Default-568h@2x~iphone.png" width="640" height="1136"/>
        <splash src="res/screen/ios/Default-667h.png" width="750" height="1334"/>
        <splash src="res/screen/ios/Default-736h.png" width="1242" height="2208"/>
    </platform>
    <icon src="res/logo/logo.png" />
    <plugin name="cordova-plugin-whitelist" spec="~1.2.1" />
    <plugin name="cordova-plugin-splashscreen" spec="~3.2.1" />
    <plugin name="cordova-plugin-geolocation" spec="~2.1.0" />
    <plugin name="cordova-plugin-camera" spec="~2.1.1" />
    <plugin name="cordova-plugin-contacts" spec="~2.0.1" />
    <plugin name="cordova-plugin-file" spec="~4.1.1" />
    <plugin name="cordova-plugin-file-transfer" spec="~1.5.0" />
    <plugin name="cordova-plugin-inappbrowser" spec="~1.3.0" />
</widget>

我的准时问题是我使用window.outerHeightwindow.outerWidth来获取高度和宽度而且它在ios上没有用,我必须使用window.innerHeightwindow.innerWidth代替