我正在创建一个Apache Cordova应用程序(使用Ionic Framework),在将cordova更新到5.4.0后,我的应用程序无法正常工作。
问题出在我的控制器MyCtrl中。 确实我需要等待 $ ionicPlatform 在我的控制器中准备好启动,所以我使用了这个源代码:
.controller('MyCtrl', function($scope, $rootScope, $http, $ionicPlatform, $ionicHistory, $cordovaDevice, $cordovaFile, $cordovaFileTransfer, $timeout, $interval, $sce, $ionicPopup) {
$ionicPlatform.ready(function() {
alert("It's working !");
});
})
在cordova 5.4.0中,此解决方案不起作用。 没有错误,$ ionicPlatform.ready被忽略。
您能帮我更新我的申请吗? 也许在控制器中使用$ ionicPlatform.ready不是一个好主意,但我不知道其他解决方案。
在我的控制器中,我需要使用这样的信息:
.controller('MyCtrl', function($scope, $rootScope, $http, $ionicPlatform, $ionicHistory, $cordovaDevice, $cordovaFile, $cordovaFileTransfer, $timeout, $interval, $sce, $ionicPopup) {
$cordovaDevice.getPlatform(); // can work before $ionicPlatform.ready
cordova.file.documentsDirectory // can work before $ionicPlatform.ready
window.requestFileSystem // can work before $ionicPlatform.ready
});
比你!
---编辑2015/11/16:
科尔多瓦版本:5.5.3
离子版:1.7.7
平台:iOS
IDE:Xcode
警告:没有警告信息
错误:没有错误消息
这是我的config.xml文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.test5119111" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" android-versionCode="15" ios-CFBundleVersion="8.4">
<name>test5</name>
<!-- <name>テスト</name> -->
<description>
テストです。
</description>
<author email="kanri@test.com" href="http://test.com/">
株式会社test
</author>
<content src="index.html"/>
<access origin="*" />
<preference name="orientation" value="portrait" />
<preference name="HideKeyboardFormAccessoryBar" value="true" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="iosPersistentFileLocation" value="Library" />
<preference name="iosPersistentFileLocation" value="Compatibility" />
<feature name="File">
<param name="ios-package" value="CDVFile" />
</feature>
<feature name="FileTransfer">
<param name="ios-package" value="CDVFileTransfer" />
</feature>
<preference name="AllowInlineMediaPlayback" value="true"/>
<preference name="DisallowOverscroll" value="true" />
<preference name="UIWebViewBounce" value="false" />
<preference name="android-minSdkVersion" value="14" />
<feature name="Device">
<param name="android-package" value="org.apache.cordova.Device" />
</feature>
<preference name="webviewbounce" value="false"/>
<preference name="UIWebViewBounce" value="false"/>
<preference name="DisallowOverscroll" value="true"/>
<preference name="android-minSdkVersion" value="16"/>
<preference name="BackupWebStorage" value="none"/>
<preference name="SplashScreen" value="screen"/>
<preference name="SplashScreenDelay" value="3000"/>
<feature name="StatusBar">
<param name="ios-package" value="CDVStatusBar" onload="true"/>
</feature>
<platform name="ios">
<icon src="resources/ios/icon/icon.png" width="57" height="57"/>
<icon src="resources/ios/icon/icon@2x.png" width="114" height="114"/>
<icon src="resources/ios/icon/icon-40.png" width="40" height="40"/>
<icon src="resources/ios/icon/icon-40@2x.png" width="80" height="80"/>
<icon src="resources/ios/icon/icon-50.png" width="50" height="50"/>
<icon src="resources/ios/icon/icon-50@2x.png" width="100" height="100"/>
<icon src="resources/ios/icon/icon-60.png" width="60" height="60"/>
<icon src="resources/ios/icon/icon-60@2x.png" width="120" height="120"/>
<icon src="resources/ios/icon/icon-60@3x.png" width="180" height="180"/>
<icon src="resources/ios/icon/icon-72.png" width="72" height="72"/>
<icon src="resources/ios/icon/icon-72@2x.png" width="144" height="144"/>
<icon src="resources/ios/icon/icon-76.png" width="76" height="76"/>
<icon src="resources/ios/icon/icon-76@2x.png" width="152" height="152"/>
<icon src="resources/ios/icon/icon-small.png" width="29" height="29"/>
<icon src="resources/ios/icon/icon-small@2x.png" width="58" height="58"/>
<icon src="resources/ios/icon/icon-small@3x.png" width="87" height="87"/>
<icon src="resources/ios/icon/iTunesArtwork" width="512" height="512"/>
<icon src="resources/ios/icon/iTunesArtwork@2x" width="1024" height="1024"/>
<splash src="resources/ios/splash/Default-568h@2x~iphone.png" height="1136" width="640"/>
<splash src="resources/ios/splash/Default-667h.png" height="1334" width="750"/>
<splash src="resources/ios/splash/Default-736h.png" height="2208" width="1242"/>
<splash src="resources/ios/splash/Default-Landscape-736h.png" height="1242" width="2208"/>
<splash src="resources/ios/splash/Default-Landscape@2x~ipad.png" height="1536" width="2048"/>
<splash src="resources/ios/splash/Default-Landscape~ipad.png" height="768" width="1024"/>
<splash src="resources/ios/splash/Default-Portrait@2x~ipad.png" height="2048" width="1536"/>
<splash src="resources/ios/splash/Default-Portrait~ipad.png" height="1024" width="768"/>
<splash src="resources/ios/splash/Default@2x~iphone.png" height="960" width="640"/>
<splash src="resources/ios/splash/Default~iphone.png" height="480" width="320"/>
</platform>
<platform name="android">
<icon src="resources/android/icon/drawable-ldpi-icon.png" density="ldpi"/>
<icon src="resources/android/icon/drawable-mdpi-icon.png" density="mdpi"/>
<icon src="resources/android/icon/drawable-hdpi-icon.png" density="hdpi"/>
<icon src="resources/android/icon/drawable-xhdpi-icon.png" density="xhdpi"/>
<icon src="resources/android/icon/drawable-xxhdpi-icon.png" density="xxhdpi"/>
<icon src="resources/android/icon/drawable-xxxhdpi-icon.png" density="xxxhdpi"/>
<splash src="resources/android/splash/drawable-land-ldpi-screen.png" density="land-ldpi"/>
<splash src="resources/android/splash/drawable-land-mdpi-screen.png" density="land-mdpi"/>
<splash src="resources/android/splash/drawable-land-hdpi-screen.png" density="land-hdpi"/>
<splash src="resources/android/splash/drawable-land-xhdpi-screen.png" density="land-xhdpi"/>
<splash src="resources/android/splash/drawable-land-xxhdpi-screen.png" density="land-xxhdpi"/>
<splash src="resources/android/splash/drawable-land-xxxhdpi-screen.png" density="land-xxxhdpi"/>
<splash src="resources/android/splash/drawable-port-ldpi-screen.png" density="port-ldpi"/>
<splash src="resources/android/splash/drawable-port-mdpi-screen.png" density="port-mdpi"/>
<splash src="resources/android/splash/drawable-port-hdpi-screen.png" density="port-hdpi"/>
<splash src="resources/android/splash/drawable-port-xhdpi-screen.png" density="port-xhdpi"/>
<splash src="resources/android/splash/drawable-port-xxhdpi-screen.png" density="port-xxhdpi"/>
<splash src="resources/android/splash/drawable-port-xxxhdpi-screen.png" density="port-xxxhdpi"/>
</platform>
</widget>
答案 0 :(得分:0)
@Officebit,
谢谢你回答问题。大多数开发人员使用 Cordova / Phonegap CLi 或 Phonegap Build 。这使你的答案有点独特。
使用config.xml
,因为您说您正在为iOS
构建,我将删除所有其他不适用的内容(即Android和Windows)。您config.xml
中有很多错误。您应该为此收到错误,但我不熟悉您的IDE。
接下来,由于Apple的ATS
系统,您应该收到网络错误。 ATS阻止您的网络访问。 (如何在一分钟内解决)你应该已经遇到ATS
;我不是100%确定你为什么还没有遇到ATS
。可能是因为你的javascript没有解雇。
此外,我将假设您在本地加载所有资产(Javascript,CSS等),而不是从Internet加载。
你应该做三(3)件事。
config.xml
。whitelist
系统,其中包括CSP
和ATS
。 <强> 1。 config.xml
在下方。
<强> 2。 HOW TO apply the Cordova/Phonegap the whitelist system 强> 3.业余时间你应该阅读:Top Mistakes by Developers new to Cordova/Phonegap
index.html
。
<meta http-equiv="Content-Security-Policy"
content="default-src *;
style-src 'self' 'unsafe-inline' 'unsafe-eval';
script-src 'self' 'unsafe-inline' 'unsafe-eval';">
Info.plist
。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Ignore this line. <There is a layout bug. here>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<widget id="com.ionicframework.test5119111"
version="0.0.1" xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0"
android-versionCode="15" ios-CFBundleVersion="8.4" />
<name>test5</name>
<!-- <name>テスト</name> -->
<description>
テストです。
</description>
<author email="kanri@test.com" href="http://test.com/">
株式会社test
</author>
<content src="index.html"/>
<!-- These are okay -->
<preference name="orientation" value="portrait" />
<preference name="HideKeyboardFormAccessoryBar" value="true" />
<preference name="AllowInlineMediaPlayback" value="true"/>
<preference name="DisallowOverscroll" value="true" />
<preference name="DisallowOverscroll" value="true"/>
<preference name="BackupWebStorage" value="none"/>
<!-- These paramters are deprecated consider using
the plugin [cordova-plugin-splashscreen]
(https://www.npmjs.com/package/cordova-plugin-splashscreen).
It has different parameters.
-->
<preference name="SplashScreen" value="screen"/>
<preference name="SplashScreenDelay" value="3000"/>
<!-- 'UIWebViewBounce' is deprecated. Use 'DisallowOverscroll' instead.
https://github.com/phonegap/build/issues/131
You need to make the change.
-->
<preference name="webviewbounce" value="false"/>
<preference name="UIWebViewBounce" value="false" />
<!-- I assume this is for the `File` plugin. -->
<preference name="iosPersistentFileLocation" value="Library" />
<preference name="iosPersistentFileLocation" value="Compatibility" />
<feature name="File">
<param name="ios-package" value="CDVFile" />
</feature>
<feature name="FileTransfer">
<param name="ios-package" value="CDVFileTransfer" />
</feature>
<feature name="StatusBar">
<param name="ios-package" value="CDVStatusBar" onload="true"/>
</feature>
<platform name="ios">
<icon src="resources/ios/icon/icon.png" width="57" height="57"/>
<icon src="resources/ios/icon/icon@2x.png" width="114" height="114"/>
<icon src="resources/ios/icon/icon-40.png" width="40" height="40"/>
<icon src="resources/ios/icon/icon-40@2x.png" width="80" height="80"/>
<icon src="resources/ios/icon/icon-50.png" width="50" height="50"/>
<icon src="resources/ios/icon/icon-50@2x.png" width="100" height="100"/>
<icon src="resources/ios/icon/icon-60.png" width="60" height="60"/>
<icon src="resources/ios/icon/icon-60@2x.png" width="120" height="120"/>
<icon src="resources/ios/icon/icon-60@3x.png" width="180" height="180"/>
<icon src="resources/ios/icon/icon-72.png" width="72" height="72"/>
<icon src="resources/ios/icon/icon-72@2x.png" width="144" height="144"/>
<icon src="resources/ios/icon/icon-76.png" width="76" height="76"/>
<icon src="resources/ios/icon/icon-76@2x.png" width="152" height="152"/>
<icon src="resources/ios/icon/icon-small.png" width="29" height="29"/>
<icon src="resources/ios/icon/icon-small@2x.png" width="58" height="58"/>
<icon src="resources/ios/icon/icon-small@3x.png" width="87" height="87"/>
<icon src="resources/ios/icon/iTunesArtwork" width="512" height="512"/>
<icon src="resources/ios/icon/iTunesArtwork@2x" width="1024" height="1024"/>
<splash src="resources/ios/splash/Default-568h@2x~iphone.png" height="1136" width="640"/>
<splash src="resources/ios/splash/Default-667h.png" height="1334" width="750"/>
<splash src="resources/ios/splash/Default-736h.png" height="2208" width="1242"/>
<splash src="resources/ios/splash/Default-Landscape-736h.png" height="1242" width="2208"/>
<splash src="resources/ios/splash/Default-Landscape@2x~ipad.png" height="1536" width="2048"/>
<splash src="resources/ios/splash/Default-Landscape~ipad.png" height="768" width="1024"/>
<splash src="resources/ios/splash/Default-Portrait@2x~ipad.png" height="2048" width="1536"/>
<splash src="resources/ios/splash/Default-Portrait~ipad.png" height="1024" width="768"/>
<splash src="resources/ios/splash/Default@2x~iphone.png" height="960" width="640"/>
<splash src="resources/ios/splash/Default~iphone.png" height="480" width="320"/>
</platform>
<access origin="*" />
</widget>
答案 1 :(得分:0)
我确认了! 此代码在cordova 5.4.0中不起作用,但在最新版本上工作(例如:cordova 5.3.3): http://ionicframework.com/docs/api/utility/ionic.Platform/
angular.module('PlatformApp', ['ionic'])
.controller('PlatformCtrl', function($scope) {
ionic.Platform.ready(function(){
alert("It's ok!");
});
});