I have a hybrid app built with PhoneGap. If I compile the app using Android Studio / XCode everything is working fine, but i want to use PhoneGap Build. When starting the app built with PhoneGap on my Android device, it doesn't work. It seems like a permission issue. My app requires internet connection and access to location services. I have no idea on how to include this in my config.xml.
Any idea?
Add this to your config.xml
<preference name="android-build-tool" value="gradle" />
<plugin name="cordova-plugin-whitelist" />
<access origin="*"/>
<allow-navigation href="*" />
<allow-navigation href="data:*" />
<allow-intent href="*" />
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-intent href="market:*" />
The wildcards will allow everything, as per the intent examples you can be more specific.
Related
Running server locally. Tested client via all browsers, works well, but once on Cordova and trying it on Simulator (as well as on device), it fails with (per Safari Technology Preview):
WebSocket connection to
'ws://192.X.X.X:5000/socket.io/?EIO=4&transport=websocket' failed:
Unexpected response code: 400
Using
Cordova version 10.0.0
Socket.IO v3.0.4 (flask-SocketIO)
Python 3.9.4
config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.X.X" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>X</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-navigation href="*" />
<allow-intent href="*" />
<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>
<plugin name="cordova-plugin-whitelist" />
<plugin name="cordova-plugin-media" />
<plugin name="cordova-plugin-firebase" />
<plugin name="cordova-plugin-device" />
<plugin name="cordova-plugin-admobpro" >
<variable name="ADMOB_APP_ID" value="X" />
</plugin>
</widget>
Any tips is more than welcome!
Thanks!
I have a Windows 10 UWP application built using Ionic/Cordova, so my http requests originate from the embedded webview.
I can run my application at home, or on a tablet connected via cell and the http requests all work. However, when I run this on any office machine (work machines), the requests other than to local host appear to be blocked. I initially thought this was the network, however using Wireshark, I can see the request if I just run them in the machine browser, but I can't see them if I run the same from the application.
If I run the application via the desktop browser (using Ionic serve), it also works. It only seems to be when it is running in the UWP container.
Since the requests don't appear in Wireshark, I have no idea how to diagnose where this is getting blocked.
How can I diagnose this (I assume the local TCP/IP stack?)
Update 1
Some more information on a minimal application
I create a new Ionic 3 application, straight from a template, and my config.xml looks something like
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.ionic.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>MyApp</name>
<description>An awesome Ionic/Cordova app.</description>
<author email="hi#ionicframework" href="http://ionicframework.com/">Ionic Framework 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:*" />
<allow-navigation href="*" />
<feature name="http://api.phonegap.com/1.0/network" />
<access origin="*" />
<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="SplashMaintainAspectRatio" value="true" />
<preference name="FadeSplashScreenDuration" value="300" />
<preference name="SplashShowOnlyFirstTime" value="false" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="3000" />
<preference name="windows-target-version" value="10.0" />
<platform name="android">
...
<platform name="ios">
...
</platform>
<engine name="windows" spec="^5.0.0" />
<plugin name="cordova-plugin-console" spec="^1.0.5" />
<plugin name="cordova-plugin-device" spec="^1.1.4" />
<plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
<plugin name="cordova-plugin-statusbar" spec="^2.2.2" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.1" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
<plugin name="cordova-plugin-wkwebview-engine" spec="^1.1.3" />
</widget>
When I build to the Window package, the AppxManifest.xml includes the following...
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
The test service should by CORS enabled, and I can connect to it via cell, and any other network I have tried except for our office network, as we have no idea where it is being blocked. I don't see anything in wireshark. If I run the same application via Ionic serve (so running in the desktop browser), then I have no problems. If I install the Windows version at home, I can connect. If I install it on a Tablet (eg Surface), then is does NOT connect if the serface is on the office WIFI, but it DOES connect if I tether the surface to my phone.
If we give the Surface a fixed IP it also then seems to work. I have no idea why the fixed IP makes a difference.
The actual test app code looks like the following (the only difference is the url to the office test server)...
export class HomePage {
public result : any;
public url : string;
constructor(public navCtrl: NavController, private http: Http) {
this.url='http://mytesturl';
}
public onClick() : void {
this.http.get(this.url).subscribe(res => {
this.result = res.statusText;
console.log(res);
}, (error : Response) => {
let json = error.json();
this.result = `failed ${error.statusText}`;
console.log(error);
});
}
}
We had the same problem and fixed it by adding the capability "privateNetworkClientServer" to the app. Perhaps that's your problem as well?
I have a major trouble with my application.
I have an application angular 2. I packaged this app with Cordova. And then with visual studio, I have built a windows application.
In my app I use WebSocket, my app uses WebSockets to send a message to a local server WS. This server is running in local through a windows service.
My problem is that I can't connect my app with the WS server. In the on error event, I don't have anything.
If I build my app on my computer and install it in this same computer it works, but if I install this app in another computer or tablet it doesn't work.
All devices are on windows 10.
Here are my config.xml from my cordova project
<?xml version="1.0" encoding="utf-8"?>
<widget defaultlocale="fr-FR" id="toto" version="1.0.0" windows-packageVersion="1.0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0" xmlns:vs="http://schemas.microsoft.com/appx/2014/htmlapps">
<content src="index.html" />
<access origin="*" />
<vs:features />
<preference name="SplashScreen" value="screen" />
<preference name="windows-target-version" value="10.0" />
<preference name="windows-phone-target-version" value="10.0" />
<preference name="WindowsDefaultUriPrefix" value="ms-appx://" />
<plugin name="cordova-plugin-whitelist" version="1" />
<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="wp8">
<splash height="1280" src="res/screens/wp8/SplashScreenImage.png" width="768" />
</platform>
<plugin name="cordova-windows-capability-localnetwork" src="https://github.com/dilhan2013/cordova-windows-capability-localnetwork.git" version="0.1.0" />
<vs:platformSpecificValues>
<vs:platformSpecificWidget platformName="windows">
</vs:platformSpecificWidget>
</vs:platformSpecificValues>
<preference name="DisallowOverscroll" value="true" />
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
<plugin name="cordova-plugin-console" version="1.0.7" />
</widget>
Thank you for your help.
Sorry in advance for my English
The problem in this particular situation comes from the fact that the app is trying to reach the Web Socket running on localhost.
Like it is mentioned as an answer to this post : Cannot connect to localhost in windows store application, developed windows store app can be isolated from loopback for security reasons.
The solution consists first in finding the installed app PackageFamilyName (this can also be done with the SID from regedit, like in the post mentioned above). For this, run this Power Shell command:
Get-AppxPackage | ? { $_.Name -like 'APP_NAME' }
APP_NAME can be part of the name you know your app has.
Once the description of the package is displayed, add the app to the NetIsolation exemption list by entering the PackageFamilyName in the following Power Shell command:
CheckNetIsolation LoopbackExempt -a -n="PackageFamilyName"
The app should now be part of the exemption list displayed with:
CheckNetIsolation LoopbackExempt -s
And it should be allowed to access the localhost.
Check your WS server, does it accept incoming requests from hosts other than localhost?
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.fornextit.southplus" version="1.0.0">
<name>South Plus</name>
<description>South Plus application that responds to the deviceready event.</description>
<author href="http://phonegap.com" email="support#phonegap.com">PhoneGap Team</author>
<content src="index.html"/>
<feature name="Notification">
<param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>
<feature name="Vibration">
<param name="android-package" value="org.apache.cordova.vibration.Vibration" />
</feature>
<preference name="phonegap-version" value="cli-5.2.0" />
<preference name="permissions" value="none"/>
<preference name="orientation" value="default"/>
<preference name="target-device" value="universal"/>
<preference name="fullscreen" value="true"/>
<preference name="webviewbounce" value="true"/>
<preference name="prerendered-icon" value="true"/>
<preference name="stay-in-webview" value="false"/>
<preference name="ios-statusbarstyle" value="black-opaque"/>
<preference name="detect-data-types" value="true"/>
<preference name="exit-on-suspend" value="false"/>
<preference name="show-splash-screen-spinner" value="true"/>
<preference name="auto-hide-splash-screen" value="true"/>
<preference name="disable-cursor" value="false"/>
<preference name="android-minSdkVersion" value="7"/>
<preference name="android-installLocation" value="auto"/>
<gap:plugin name="org.apache.cordova.battery-status"/>
<gap:plugin name="org.apache.cordova.camera"/>
<gap:plugin name="org.apache.cordova.media-capture"/>
<gap:plugin name="org.apache.cordova.console"/>
<gap:plugin name="org.apache.cordova.contacts"/>
<gap:plugin name="org.apache.cordova.device"/>
<gap:plugin name="org.apache.cordova.device-motion"/>
<gap:plugin name="org.apache.cordova.device-orientation"/>
<gap:plugin name="org.apache.cordova.dialogs"/>
<gap:plugin name="org.apache.cordova.file"/>
<gap:plugin name="org.apache.cordova.file-transfer"/>
<gap:plugin name="org.apache.cordova.geolocation"/>
<gap:plugin name="org.apache.cordova.globalization"/>
<gap:plugin name="org.apache.cordova.inappbrowser"/>
<gap:plugin name="org.apache.cordova.media"/>
<gap:plugin name="org.apache.cordova.network-information"/>
<gap:plugin name="org.apache.cordova.splashscreen"/>
<gap:plugin name="org.apache.cordova.vibration"/>
<plugin name="Notification" value="org.apache.cordova.Notification"/>
<icon src="icon.png"/>
<icon src="www/res/icon/android/icon-36-ldpi.png" gap:platform="android" gap:qualifier="ldpi"/>
<icon src="www/res/icon/android/icon-48-mdpi.png" gap:platform="android" gap:qualifier="mdpi"/>
<icon src="www/res/icon/android/icon-72-hdpi.png" gap:platform="android" gap:qualifier="hdpi"/>
<icon src="www/res/icon/android/icon-96-xhdpi.png" gap:platform="android" gap:qualifier="xhdpi"/>
<icon src="www/res/icon/blackberry/icon-80.png" gap:platform="blackberry"/>
<icon src="www/res/icon/blackberry/icon-80.png" gap:platform="blackberry" gap:state="hover"/>
<icon src="www/res/icon/ios/icon-57.png" gap:platform="ios" width="57" height="57"/>
<icon src="www/res/icon/ios/icon-72.png" gap:platform="ios" width="72" height="72"/>
<icon src="www/res/icon/ios/icon-57-2x.png" gap:platform="ios" width="114" height="114"/>
<icon src="www/res/icon/ios/icon-72-2x.png" gap:platform="ios" width="144" height="144"/>
<icon src="www/res/icon/webos/icon-64.png" gap:platform="webos"/>
<icon src="www/res/icon/windows-phone/icon-48.png" gap:platform="winphone"/>
<icon src="www/res/icon/windows-phone/icon-173-tile.png" gap:platform="winphone" gap:role="background"/>
<gap:splash src="www/res/screen/android/screen-ldpi-portrait.png" gap:platform="android" gap:qualifier="port-ldpi"/>
<gap:splash src="www/res/screen/android/screen-mdpi-portrait.png" gap:platform="android" gap:qualifier="port-mdpi"/>
<gap:splash src="www/res/screen/android/screen-hdpi-portrait.png" gap:platform="android" gap:qualifier="port-hdpi"/>
<gap:splash src="www/res/screen/android/screen-xhdpi-portrait.png" gap:platform="android" gap:qualifier="port-xhdpi"/>
<gap:splash src="www/res/screen/blackberry/screen-225.png" gap:platform="blackberry"/>
<gap:splash src="www/res/screen/ios/screen-iphone-portrait.png" gap:platform="ios" width="320" height="480"/>
<gap:splash src="www/res/screen/ios/screen-iphone-portrait-2x.png" gap:platform="ios" width="640" height="960"/>
<gap:splash src="www/res/screen/ios/screen-iphone-portrait-568h-2x.png" gap:platform="ios" width="640" height="1136"/>
<gap:splash src="www/res/screen/ios/screen-ipad-portrait.png" gap:platform="ios" width="768" height="1024"/>
<gap:splash src="www/res/screen/ios/screen-ipad-landscape.png" gap:platform="ios" width="1024" height="768"/>
<gap:splash src="www/res/screen/windows-phone/screen-portrait.jpg" gap:platform="winphone"/>
<access origin="*"/>
<access origin="127.0.0.1*"/>
<plugin name="cordova-plugin-whitelist" version="1"/>
<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 my config.xml
phonegap build isnt accepting simplest of simple single index file. it worked before. dont know what change they bought over. now its not working. please somebody suggest.
i am getting this error: Error - Some official plugins have to be updated if using PhoneGap >= 4.0.0. Please upgrade the version of any plugins that may include the following file: FileTransfer.java - You can fix this here
#amar,
last weekend an unannounced change was made to Phonegap Build, if you do not set the version of your compiler, you now get cli-5.2.0. This has broken many, many programs. Input your error string in the search, and you will see it.
Here is what you need to know:
From the Phonegap Build Forum, Petra Adds:
I would add: without announcement, PGB changed the default PGB-version from 3.7.0 to cli-5.2.0. This causes all those who have not set 'phonegap-version' in config.xml to be confronted with the sudden need of splashscreen and whitelist plugins and additional whitelisting specifications in config and html.
Also, several plugins seem not to build correctly with cli-5.2.0, causing log file error messages about "Class ***.java".
FWIW: Phonegap Build admitted to as much in this tweet
QUICK FIX Add this to your config.xml
<preference name="phonegap-version" value="3.7.0" />
From Top Mistakes by Developers new to Cordova/Phonegap you have hit:
#6 Not setting the "phonegap version" for your compiler
#7 Not setting "version" for you plugins
#10 Not adding the new "white-list" and "white-list plugin" parameters in config.xml.
For #6 & #7
With the CLI version, if you do not assign a version for your platform OR in ''Phonegap Build'' if you do not set the phonegap-version in config.xml, YOU WILL GET THE LATEST VERSION. If you are lucky, your program just works as expected. If you are not lucky, you'll get a set of cascading errors.
Luckily for all of us, Holly Schinsky has written a nice blog post to explain it all:
Cordova/PhoneGap Version Confusion
http://devgirl.org/2014/11/07/cordovaphonegap-version-confusion/
For #10
This relatively * NEW * requirement means – to access ANY website or resources on the web, you MUST use the whitelist and the whitelist plugin. This requirement goes into affect, if you are using cordova-android#4.0.0 or better; including cli-5.1.1. If however, your version is before 4.0.0, let's say 3.5.0 or 3.7.0, then you will not have to add the white-list requirement.
To be clear, the "whitelist" has been around for a bit, but the plugin and requirement is very new. As you would expect, when the "whitelist" was added, the defacto open-access feature was deprecated. Or said another way, the defacto open-access feature was planned and scheduled to be eliminated. This change marks a step in removal of the open-access feature.
In addition, the Content Security Policy (CSP) has caught numerous developers - because it was soooo poorly publicized. Depending on your use and the version of Phonegap you are using, the CSP needs to go in every single HTML page you used, just like you have to wait for 'deviceready'. However, there are cases where it is not needed at all. The documentation is confusing for some, please read it carefully. The documentation is buried in the bottom of many of the latest documentation pages.
Related Links
Phonegap Build Forum: Notes for upgrading to cli-5.1.1 on PGB and now required Whitelist
Cordova Whitelist Guide
Phonegap Whitelist Guide
Phonegap Build Whitelist Guide
I'm trying to update an app to a newer version and I am unable to get my login scripts to work anymore in v 5.1.1 of Cordova.
I have the whitelist plugin installed according to cordova and inappbrowser allows me access to the internet.
I shortened the config.xml to allow all connections. I think
Config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="org.company.app" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>app</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-navigation href="*" />
<allow-intent href="*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
</widget>
Cordova Plugin list.
cordova-plugin-console 1.0.1 "Console"
cordova-plugin-file 3.0.0 "File"
cordova-plugin-file-transfer 1.2.1 "File Transfer"
cordova-plugin-inappbrowser 1.0.1 "InAppBrowser"
cordova-plugin-media-capture 1.0.1 "Capture"
cordova-plugin-network-information 1.0.1 "Network Information"
cordova-plugin-whitelist 1.0.0 "Whitelist"
So I moved
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
to the top of my plist file and it started working. I previously had it at the bottom. Not totally sure why it worked but it did.