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" />
Related
I am trying to create my first ios cordova app via Volt Builder online build service (successor to Phonegap Build) which uses cordova 11 + cordova-ios 6.2.0.
When I try to load a local file from the www folder with an ajax call I get an error on the app. The code works fine in Chrome desktop and almost identical code works in several android apps, so I believe the problem lies in config.xml and not the code itself.
whatever code is in comments, I have tried some combination of it without success.
(I am also aware that "async: false" doesn't work on iOS)
index.html
//$.support.cors = true;
$.ajax({
//async: false,
type: "GET",
url: "lang/en/strings.xml",
dataType: "text",
//cache: false,
//headers: { "cache-control": "no-cache" },
success: function(data) { /*do stuff here*/ },
error: function(e){ alert(e.statusText); }
});
config.xml (the relevant stuff only)
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<plugin name="cordova-plugin-network-information" />
<plugin name="cordova-plugin-inappbrowser" />
<plugin name="cordova-plugin-browser" source="npm"/>
<plugin name="cordova-plugin-dialogs" />
<plugin name="cordova-plugin-device" />
<plugin name="cordova-plugin-file" />
<plugin name="cordova-plugin-filepath" source="npm"/>
<platform name="ios">
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
<preference name="WKWebViewOnly" value="true" />
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<!--<plugin name="#globules-io/cordova-plugin-ios-xhr" source="npm" version="1.0.3" />-->
<plugin name="cordova-plugin-wkwebview-engine" source="npm"/>
<plugin name="cordova-plugin-wkwebviewxhrfix" source="npm" />
<!--<plugin name="cordova-plugin-wkwebview-file-xhr" source="npm"/>-->
<!--<plugin name="#ahovakimyan/cordova-plugin-wkwebviewxhrfix" source="npm" />-->
</platform>
I have tried so many combinations of the above plugins that I have lost count, but all I get on the app is the 'error' alert.
I am aware of the following similar questions, but couldn't get it to work for me
Local (!) AJAX-Requests fail without error message in cordova-based app only in iOS
Why is jQuery Ajax not working in Cordova iOS app
In-app AJAX not working in iOS with Cordova 10
As I found out the hard way, you cannot define a plugin inside the <platform name="ios">, but have to do so globally.
Just the <plugin name="cordova-plugin-wkwebview-file-xhr" source="npm" version="3.0.0" /> (in the right place..) get's the job done.
<!-- more plugins/etc here-->
<plugin name="cordova-plugin-wkwebview-file-xhr" source="npm" version="3.0.0" />
<platform name="ios">
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
<preference name="WKWebViewOnly" value="true" />
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<!-- more stuff here -->
</platform>
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
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.
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 *">
I'm new to Blackberry. I use phonegap to create cross platform applications. My html file is very simple. It looks like this:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" id="viewport" content="height=device-height,width=device-width,user-scalable=no" />
<title>Insert title here</title>
<script type="text/javascript" charset="utf-8" src="www/phonegap-1.3.0.js"></script>
</head>
<body>
<p>Hello World</p>
</body>
</html>
I have added phonegap-1.3.0.js file that is available for blackberry phonegap.
My config.xml contains these permissions:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0.0">
<name>Cps1</name>
<feature id="blackberry.app" required="true" version="1.0.0.0"/>
<feature id="blackberry.app.event" required="true" version="1.0.0.0"/>
<feature id="blackberry.system" required="true" version="1.0.0.0"/>
<feature id="com.phonegap" required="false" version="1.0.0"/>
<feature id="blackberry.system.event" required="true" version="1.0.0.0"/>
<feature id="blackberry.invoke" required="true" version="1.0.0.0"/>
<feature id="blackberry.invoke.BrowserArguments" required="true" version="1.0.0.0" />
<feature id="blackberry.identity" required="true" version="1.0.0.0"/>
<feature id="blackberry.utils" required="true" version="1.0.0.0"/>
<content src="index.html"/>
</widget>
On debugging it shows "Reference error: Com is not defined" in phonegap.js file. Can anyone please help me as what else has to be done?
Check the version number of phonegap u added and try with
and check the phone gap jar file is added to u r project or not??