Getting blank page in angular cordova app - ios

I'm trying to run a HelloWorld application in Angular + Cordova, but it does not work well when I run it with the ios emulator (iPhone 12 Pro Max - iOS 14.4). I'm getting a blank page (screenshot below).
I have already changed the href="/" in my index.html to href="./" but it doesn't work. I added ios platform with "cordova platform add ios" command line and I have installed all the requirements as: XCode, ios-deploy and CocoaPods tools.
I created the Angular project with Angular CLI and did not modify anything. After, I created the Cordova project inside and linked the dist folder to the www folder.
Versions:
Cordova version 10.0.0 - Angular version 11.2.9 - Angular CLI version 11.2.8 - Node version 15.14.0
Blank Page Screenshot
this is the config.xml file:
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>HelloCordova</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
this is the index.html file in www folder:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HelloWorldAngularCordova</title>
<base href="./">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.3ff695c00d717f2d2a11.css"></head>
<body>
<app-root></app-root>
<script src="runtime.7b63b9fd40098a2e8207.js" defer></script><script src="polyfills.00096ed7d93ed26ee6df.js" defer></script><script src="main.80cad638da592e13f2e3.js" defer></script></body>
</html>
Where is my error(s)? Thanks

You need to add
<script type=”text/javascript” src=”cordova.js”></script>
in your index.html file.
Then in main.ts:
let onDeviceReady = () => {
platformBrowserDynamic().bootstrapModule(AppModule);
};document.addEventListener('deviceready', onDeviceReady, false);
like here:
binding angular with cordova

Related

How to load sub index.html page to localhost in cordova ios

I am working on an ios project with cordova wkwebkit.
Of course, I know that cordova recommends spa.
In the case of the main index.html file, the page was opened on localhost as shown below in config.xml.
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="ios">
<preference name="scheme" value="app" />
<preference name="hostname" value="localhost" />
</platform>
Then you can see that the result of checking in Chrome developer mode is applied successfully.
enter image description here
But in the case of the sub index.html file, I don't know how to load it on localhost.
solution is required.
Currently, we are loading the sub index.html file with the file protocol.
enter image description here
file path:
(main) index.html path : www/index.html
(sub) index.html path : www/world/wikitude_AR/inedex.html
version:
cordova - 11
cordova ios - 6.2

ionic 4 iOS app stuck at splash screen on iOS 13+

config.xml
<xml version='1.0' encoding='utf-8'?>
<widget id="com.leo9.gameofplan" version="0.0.4" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Game Of Plan</name>
<description>The Game of Plan app is designed to: Capture your Thoughts and Feelings and convert it into Tangible Action Plan.</description>
<author email="info#leo9studio.com" href="https://leo9studio.com/">Le9studio Team</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<preference name="ScrollEnabled" value="false" />
<preference name="WKWebViewOnly" value="true" />
<preference name="CordovaWebViewEngine" value="CDVUIWebViewEngine" />
<preference name="android-minSdkVersion" value="19" />
<preference name="android-targetSdkVersion" value="28" />
<preference name="BackupWebStorage" value="none" />
<preference name="DisallowOverscroll" value="true" />
<preference name="AutoHideSplashScreen" value="false" />
<preference name="SplashScreenDelay" value="10000" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="30000" />
<preference name="OverrideUserAgent" value="Mozilla/5.0 Google" />
<allow-navigation href="*" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-plugin-statusbar" spec="^2.4.2" />
<plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
<plugin name="cordova-plugin-ionic-webview" spec="^4.0.0">
<variable name="ANDROID_SUPPORT_ANNOTATIONS_VERSION" value="27.+" />
</plugin>
<plugin name="cordova-plugin-network-information" spec="~2.0.1" />
<plugin name="cordova-plugin-secure-storage" spec="^3.0.2" />
<plugin name="cordova-plugin-screen-orientation" spec="^3.0.2" />
</widget>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Game of Plan</title>
<base href="." />
<meta name="viewport"
content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="format-detection" content="telephone=no" />
<meta http-equiv="Content-Security-Policy"
content="font-src 'self' data:; img-src * data:; default-src gap://ready file://* *; script-src 'self' 'unsafe-inline' 'unsafe-eval' * ; style-src 'self' 'unsafe-inline' *">
<meta name="msapplication-tap-highlight" content="no" />
<link rel="icon" type="image/png" href="assets/icon/favicon.png" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
</head>
<body>
<app-root></app-root>
</body>
</html>
here i attache my config.xml and index.html file.
my app is stuck at splash screen in ios13+ devices. for that reasons the app is rejected for publish for app store. i tried many thing to resolve this error. degrade splash screen plugin that wont work, also added some splash screen related config line into config.xml that also wont work.
what should be the solution?
Yu should add the following code inside your <platform name="ios"> tag:
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
Taken from here: https://cordova.apache.org/howto/2020/03/18/wkwebviewonly.html
I have never used Cordova splashscreen but looking at your config.xml content I see that you have a duplicate SplashScreenDelay preference, one has a value of 30000, the equivalent of 30 seconds and the other has a value of 10000, this can be the reason behind the problem. I would remove the duplicate preference and set the time value to 5000 (5 seconds), I would also add AutoHideSplashScreen preference and set it to false, then add the a timer in the deviceready event handler:
function onDeviceReady() {
setTimeout(function () {
navigator.splashscreen.hide();
}, 5000);
}
It should be explained in here. Check this too.
I hope this helps.

Phonegap build app not working for iOS

I'm building mobile app using phonegap build. I have build app for iOS, Android and windows and I'm testing it in TestObject. What I'm doing in my app is redirecting to http://google.com on page load itself.
index.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" charset="utf-8">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, true);
}
function onDeviceReady() {
window.location.href = "http://google.com";
}
</script>
</head>
<body onload="onLoad();">
</body>
</html>
config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.newApp.mobileApp"
versionCode = "1"
version = "1.0.0" >
<!-- versionCode is Android only -->
<!-- version is in major.minor.patch format -->
<name>My New App</name>
<description>
An example for phonegap build app which wont show up in the playstore.
</description>
<author href="https://YourWebsite.com" email="yourEmail#goesHere.com">
Name Of The Author
</author>
<plugin name="cordova-plugin-whitelist" source="npm"/>
</widget>
While testing with android (apk file), it is redirecting to google.com. But when I test with iOS device (ipa file), it is showing blank page only.
Why it is not working for iOS?
Can anyone help me to fix this? Thanks in advance.
<access origin="*" launch-external="yes" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<access origin="http://127.0.0.1*"/>
<allow-navigation href="*"/>
<allow-intent href="*"/>
to be on safe side regarding whitelist , i use these intents in my app
in addition to above , i added this plugins for Android
<gap:plugin name="cordova-plugin-whitelist" version="1.1.0" source="npm" />
and for IOS
<plugin name="cordova-plugin-whitelist" spec="https://github.com/apache/cordova-plugin-whitelist.git" />

Phonegap app Content-Security-Policy

I'm bulding an app with cordova. I'm using phonegap serve to load the app with phonegap developer app.
In index.html:
<meta http-equiv="Content-Security-Policy" content="default-src gap: file: tel: *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">
(I've also tried without file: tel:, result is the same)
I can verify that this is prepared correctly in platforms/browser/www/index.html
Then I open phonegap app in iPad, I run phonegap serve, I open Safari development tools, press connect and there it is:
Refused to load gap://ready because it appears in neither the child-src directive nor the default-src directive of the Content Security Policy.
In index.html I can see that the directive has been transformed to:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
Is there a way to make ipad to load the directive correctly?
EDIT
I've also tried to compile phonegap app developer with CSP directive in index.html, result is the same
EDIT - 1
I've also downloaded the zip file from http://192.168.1.130:3200/__api__/appzip (this is where I have my phonegap serve server) and index.html is already transformed!
The strange here is that platforms/browser/www/index.html is not transformed, so there is some process in-between that is transforming the CSP.
In my config.xml I've this directives:
<content src="index.html" />
<access origin="*" />
<access origin="cdvfile://*" />
<access launch-external="yes" origin="tel:*" />
<!-- Allowed WebView navigations -->
<allow-navigation href="http://*"/>
<allow-navigation href="https://*"/>
<allow-navigation href="http://*/*"/>
<allow-navigation href="https://*/*"/>
<allow-navigation href="data:*"/>
<allow-navigation href="about:*"/>
<allow-navigation href="tel:*"/>
<allow-navigation href="gap:*" />
<!-- Allowed URLs to be opened from the app -->
<allow-intent href="http://*"/>
<allow-intent href="https://*"/>
<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="geo:*"/>
<allow-intent href="cdvfile://*" />
It was related to this issue: https://github.com/creationix/nvm/issues/1361
Mainly, bash was detecting that v6.4.2 and pointing to it (which phonegap was pointing to correct version) but when executing phonegap from command line, it was executing v6.0.2, which probably was not setting up the correct CSP.

Cordova AJAX request not working

I'm using Cordova 5.3.1, and I seem to be totally unable to make any network requests without errors. If I add
$.ajax( "http://foo.bar.com/getfeed" )
.done(function() {
alert( "success" );
})
.fail(function(jqXHR, textStatus, errorThrown) {
alert( errorThrown );
})
.always(function() {
alert( "complete" );
});
to index.js it fails and alerts Error: SecurityError: DOM Exception 18 in iOS and SecurityError: Failed to execute 'open on 'XMLHttpRequest': Refused to connect to 'http://foo.bar.com/getfeed' because it violates the document's Content Security Policy., so it look like CORS is being blocked.
Currently the whitelist plugin doesn't install properly when you install it as per this SO post and this JIRA issue, basically it requires the iOS platform >=4.0.0-dev. I can still force it to install an older version with:
cordova plugin add cordova-plugin-whitelist#1.0.0
as per the suggestions in the SO post and JIRA issue.
However I am still unable to make any http requests to external domains. I still get the same 'DOM Exception 18' error. My config.xml file is currently
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.company.pearstest" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>CORS test</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev#cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" version="1" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
The tag for allowing different origins seems to have changed over different versions lately and as a result I've tried every conceivable combination of various different tags in this file.
I've also checked $.support.cors to make sure that jQuery allows CORS and it does (jQuery is working properly as the AJAX requests are running the fail callback rather than silently failing).
I also have the meta tag
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:">
in index.html. I suspect this isn't an issue with my emulator blocking http requests as it's a problem in both Android and iOS emulators and on an Android device.
Does anyone have any idea why I'm still having CORS issues? Thanks.
Have you tried configuring your Content-Security-Policy to look like:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
Note the * in default-src and use of ; - I've also included some other instructions in the example above to allow common JS libraries to work... this is what I use in JQuery / Handlebars Cordova 5 apps I am building for Android and iOS.
For iOS, if you're building for iOS9 and you want to be able to hit unsecured endpoints, you will have to edit your plist file. This gist has instructions.
I'm personally still having issues with Cordova 5.3.1 and Android cross-domain ajax requests. This stuff all worked fine on the older version of Cordova.
[EDIT] Android required the whitelist plugin in order for ajax requests to work. Janky IMO, but happy to have ajax working again on android.
What worked for me :
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src *">

Resources