Can I use indexedDB in a cordova iOS application? - ios

I'm getting an InvalidAccessError when I try to open a Indexed Database in my cordova iOS application.
Platform:
cordova: 5.4.1
cordova-ios: 4.0.1
iOS 9.2 (simulator and real device)
I already added the Plugin to use the WKWebview which made the the indexedDB object at least defined, but the error is thrown. The code works in chrome, safari and mobile safari if I run it via cordova's own web server.
config.xml looks like this
<content src="index.html" />
<plugin name="cordova-plugin-whitelist" spec="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>
<feature name="CDVWKWebViewEngine">
<param name="ios-package" value="CDVWKWebViewEngine" />
</feature>
<preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
and I try to open the indexedDB with this:
openDb: function() {
var openRequest = window.indexedDB.open(DB_NAME, DB_VERSION);
openRequest.onupgradeneeded = function(event) {
console.log('upgrade needed');
console.log(event);
myIndexDb = event.target.result;
var options = {
autoIncrement: true,
keyPath: 'key'
};
var objectStore = myIndexDb.createObjectStore(DB_STORE_NAME, options);
};
openRequest.onerror = function(event) {
console.log(event);
console.log('indexDB open Error!');
};
openRequest.onsuccess = function(event) {
console.log('open success');
myIndexDb = this.result;
};
openRequest.onblocked = function(event) {
console.log('request is blocked');
console.log(event);
}
}

At the moment it works with the Telerik Plugin https://github.com/Telerik-Verified-Plugins/WKWebView (and cordova-ios 3.9.2)

EDIT:
Looks like IndexedDB problems were fixed on iOS 10, and also added it to UIWebView.
OLD ANSWER:
The way to workaround the problem with cordova-plugin-wkwebview-engine and IndexedDB is to use a local webserver.
You can use the wkwebview-engine-localhost plugin to workaround the bug adding the local webserver. To install the plugin use
cordova plugin add https://github.com/apache/cordova-plugins/tree/master/wkwebview-engine-localhost

Related

Stripe in wkwebview open a browser page loading script

we're moving with our APP to new new wkweview due to the apple requirements.
One of APPs, is using StripeJS sdk in order to allow payment in app. Problem occurs when APP is bootstraping and the stripe sdk is include with the following code:
// Payment service is not initialized yet
$.ajax({
type: "GET",
cache: true,
url: "https://js.stripe.com/v3/",
dataType: "script",
error: function(XMLHttpRequest, textStatus, errorThrown) {
Logger.error("An error ocurred during SDK download");
def.reject();
},
success: function() {
Logger.debug("Stipe JDK downloaded correctly");
initialized = true;
def.resolve();
}
});
We already tried to use '' head tag in the index.html or creating dynamically one script TAG and appenging it to the body: but no one fix the problem.
Script Inclusion Tests
[Angular $http method]
$http({
method: "GET",
url: "https://js.stripe.com/v3/"
}).then(
function(res) {
angular.element("body").append("<script>" + res.data + "</script>");
}, function(err) {
def.reject();
});
[index.html]
<html>
<head>
<script type="text/javascript" src="https://js.stripe.com/v3/"></script>
...
Problem
A browser page is opened and APP is left in the background; being more specific, the "METRICS_CONTROLLER" case is catch in switch at row 767 ( see library at url < https://js.stripe.com/v3/ > ).
Have anyone an idea why including that script the browser page is opened ?
just to answer my question we found the problem.
The problem was about permission to navigate url not allowed by the cordova configuration ( file 'config.xml' ).
More specifically, we need to add the following row in our config. file
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
So finally, our CORS permission definition is:
<access origin="*" />
<allow-intent href="sms:*" />
<allow-intent href="tel:*" />
<allow-intent href="geo:*" />
<allow-intent href="mailto:*" />
<allow-intent href="file://*/*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
'*' is due to the fact that the APP can trigger outside resource, so we cannot known which url will be opened by user in APP.
Hope this help #saperlipopette
Simon

OAuth with facebook/gmail is not working on iOS simulator (Cordova app + Firebase)

I am trying to finish my last thing on cordova (+Firebase) mobile app and stuck with a problem.
So, I was working on social login for cordova app,
I was following this guide - Link to guide
when I've finished, I had some problems, but fixed them (only on android)
on iOS, when u click on some of login button - nothing happens,
BUT, when I hide the app (or just close it) and open it again, it start making redirect.
In that redirect I'm making login with facebook/gmail and then it redirects me to the link that I have in my config.xml
here is my request:
await firebase.auth().signInWithRedirect(provider);
const user = await firebase.auth().getRedirectResult();
, it works okay on android
and here is my config.xml (I've tried a lot of stuckoverflow and github solution there, so it can look messy
<?xml version='0.0.1.2' encoding='utf-8'?>
<widget id="com.appname.ios" version="0.0.1.2" xmlns="http://www.w3.org/ns/widgets">
<name>App name</name>
<description>
Some description...
</description>
<author email="example#gmail.com" href="https://appname.com">
App ame
</author>
<content src="index.html" />
<icon src="/public/favicon.ico" />
<universal-links>
<host name="appname.page.link" scheme="https" />
<host name="appname.com" scheme="https">
<path url="/__/auth/callback"/>
</host>
</universal-links>
<plugin name="cordova-plugin-whitelist" spec="1" />
<plugin name="cordova.plugins.diagnostic" />
<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="*"/>
<platform name="android">
<allow-intent href="market:*" />
</platform>
<preference name="AndroidLaunchMode" value="singleTask" />
<preference name="orientation" value="portrait" />
<preference name="CordovaWebViewEngine" value="CDVUIWebViewEngine" />
<platform name="ios">
<icon src="public/ios/60.png" width="180" height="180" />
<icon src="public/ios/60.png" width="60" height="60" />
<icon src="public/ios/76.png" width="76" height="76" />
<icon src="public/ios/40.png" width="40" height="40" />
<icon src="public/ios/57.png" width="57" height="57" />
<icon src="public/ios/72.png" width="72" height="72" />
<icon src="public/ios/167.png" width="167" height="167" />
<icon src="public/ios/29.png" width="29" height="29" />
<icon src="public/ios/50.png" width="50" height="50" />
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<splash src="public/ios/appname.png" width="320" height="480"/>
<splash src="public/ios/appname.png" width="640" height="960"/>
<splash src="public/ios/appname.png" width="768" height="1024"/>
<splash src="public/ios/appname.png" width="1536" height="2048"/>
<splash src="public/ios/appname.png" width="1024" height="768"/>
<splash src="public/ios/appname.png" width="2048" height="1536"/>
<splash src="public/ios/appname.png" width="640" height="1136"/>
<splash src="public/ios/appname.png" width="750" height="1334"/>
<splash src="public/ios/appname.png" width="1242" height="2208"/>
</platform>
</widget>
And here is a screen shot of what I have when I make success login:
ios simulator screenshot
Already fixed by doing next things:
On iOS social button was not even redirecting to appropriate provider because of some error that was stopping whole stack:
found answer here - fixedBugLink
After I've fixed that error, next things I was dealing with was that I could not return back to app after successful login
So I found that the problem was in unappropriate adding the next plugin -
https://www.google.com/search?q=cordova+url+scheme+ios&oq=cordova+url+scheme+ios&aqs=chrome..69i57j0j69i60.2808j0j4&sourceid=chrome&ie=UTF-8
I fixed problem with wrong URL scheme link, by changing the default one to
REVERSED_CLIENT_ID from GoogleService-Info.plist file in my iOS app.
So be careful with following guides (by the way I've followed this one - oauth-cordva-firebase
Hope this will help someone too :)

What is the Parent Tag for <edit-config in config,xml in cordova ios project?

I update an iOS app and it was rejected with below email
Missing Info.plist key - This app attempts to access privacy-sensitive
data without a usage description. The app's Info.plist must contain an
NSPhotoLibraryUsageDescription key with a string value explaining to
the user how the app uses this data.
I try to add below xml tag to config.xml.
<edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
<string>Need camera access to take pictures</string>
</edit-config>
<edit-config file="*-Info.plist" mode="merge" target="NSPhotoLibraryUsageDescription">
<string>Need to photo library access to get pictures from there</string>
</edit-config>
But I am not sure under which tag I need to
My config.xml file.
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.aotsinc.christian.iphone.biblequizcompanion" version="3.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Bible Quiz Companion</name>
<description>
Bible Quiz Companion is a free app useful for the users to prepare for Jounior Bible Quiz Compatition.
</description>
<author email="dev#cordova.apache.org" href="http://cordova.io">
Alpha Omega Tech Solutions Inc.
</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>
<engine name="ios" spec="^4.5.4" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-plugin-x-socialsharing" spec="^5.2.1" />
<plugin name="cordova-plugin-camera" spec="^4.0.1" />
<plugin name="cordova-plugin-tts" spec="^0.2.3" />
<plugin name="cordova-plugin-apprate" spec="^1.3.0" />
<plugin name="com.darktalker.cordova.screenshot" spec="git+https://github.com/gitawego/cordova-screenshot.git" />
</widget>
Thanks for your help
EDIT 1
I try to add the code that you gave in plugin.xml inside camera plugin as below. But I didn't see this entry in the info.plist. Can you please tell me whether my change in the plugin.xml is correct. Thanks
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="Camera">
<param name="ios-package" value="CDVCamera" />
</feature>
<preference name="CameraUsesGeolocation" value="false" />
</config-file>
<js-module src="www/ios/CameraPopoverHandle.js" name="CameraPopoverHandle">
<clobbers target="CameraPopoverHandle" />
</js-module>
<preference name="CAMERA_USAGE_DESCRIPTION" default=" " />
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string>Need camera access to take pictures</string>
</config-file>
<preference name="PHOTOLIBRARY_USAGE_DESCRIPTION" default=" " />
<config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
<string>Need to photo library access to get pictures from there</string>
</config-file>
<header-file src="src/ios/UIImage+CropScaleOrientation.h" />
<source-file src="src/ios/UIImage+CropScaleOrientation.m" />
<header-file src="src/ios/CDVCamera.h" />
<source-file src="src/ios/CDVCamera.m" />
<header-file src="src/ios/CDVJpegHeaderWriter.h" />
<source-file src="src/ios/CDVJpegHeaderWriter.m" />
<header-file src="src/ios/CDVExif.h" />
<framework src="ImageIO.framework" weak="true" />
<framework src="CoreLocation.framework" />
<framework src="CoreGraphics.framework" />
<framework src="AssetsLibrary.framework" />
<framework src="MobileCoreServices.framework" />
<framework src="CoreGraphics.framework" />
<framework src="AVFoundation.framework" />
</platform>
see docs
In your config.xml as a child node of <platform name="ios"> add:
<edit-config target="NSPhotoLibraryUsageDescription" file="*-Info.plist" mode="merge">
<string>need to photo library access to get pictures from there</string>
</edit-config>
Use config-file instead of edit-config below PLATFORM tag in PLUGIN.XML file of your plugin that need this:
<platform name="ios">
<preference name="CAMERA_USAGE_DESCRIPTION" default=" " />
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string>Need camera access to take pictures</string>
</config-file>
<preference name="PHOTOLIBRARY_USAGE_DESCRIPTION" default=" " />
<config-file target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
<string>Need to photo library access to get pictures from there</string>
</config-file>
</platform>

Allow call (and maps, and mail) in cordova

I've been struggling with this for a while. I'm trying to make a call after people press 'Call' from a popup. Funny thing is, that it goes straight to calling when they click the phone number. But when they hit 'Call', console returns:
ERROR Internal navigation rejected - <allow-navigation> not set for url='tel:06-83237516
Code:
Controller:
$scope.callPerson = function() {
var link = "tel:" + $scope.person.phonenumber;
var confirmTel = $ionicPopup.confirm({
title: $scope.person.phonenumber,
cancelText: 'Cancel',
okText: 'Call'
});
confirmTel.then(function(res) {
if (res) {
window.open(link);
} else {
console.log('cancel call');
}
});
}
Config.xml:
<access origin="*"/>
<allow-intent href="tel:*"/>
<allow-intent href="mailto:*"/>
<access origin="tel:*" launch-external="yes"/>
<access origin="mailto:*" launch-external="yes"/>
html:
<div ng-click="callPerson()"> {{person.phonenumber}}</div>
With Mail, it doesn't work at all, and returns an identical error.
Same for opening maps. It does work in the PhoneGap test app, but not when deployed.
Maps code:
$scope.openmaps = function() {
var address = $scope.person.adres + ", " + $scope.person.plaats;
var url = '';
if (ionic.Platform === 'iOS' || ionic.Platform === 'iPhone' || navigator.userAgent.match(/(iPhone|iPod|iPad)/)) {
url = "http://maps.apple.com/maps?q=" + encodeURIComponent(address);
} else if (navigator.userAgent.match(/(Android|BlackBerry|IEMobile)/)) {
url = "geo:?q=" + encodeURIComponent(address);
} else {
url = "http://maps.google.com?q=" + encodeURIComponent(address);
}
window.open(url);
};
May be it is too late but I want to comment so that other users couldn't face this issue.
Because I didn't find any working solution anywhere.
You need to add
<allow-navigation href="tel:*" /> in config.xml
I was facing same issue for mailto intent. It was working when I tried it directly
<a onclick="mailto:test#me.com">Email</a>
But I got an error when I tried to call it using javascript window.location.href = 'mailto:test#me.com
internal navigation rejected - <allow-navigation> not set for url='mailto:test#me.com'
All you need to is to add allow-navigation in your config.xml
So your config.xml will be:
<access origin="mailto:*" launch-external="yes"/>
<allow-intent href="mailto:*" />
<plugin name="cordova-plugin-whitelist" version="1" />
<allow-navigation href="mailto:*" />
I use this config in config.xml
for ios
<allow-navigation href="tel:*" />
for android
<allow-intent href="tel:*"/>
Altering Cordova's WhiteListPlugin in config.xml did not work for me -- <access >,`. I tried many combinations, including those above. Doesn't mean these won't work necessarily, just for my setup it doesn't. (Building for Browser, Android, and iOS)
However, using the Cordova InAppBrowser Plugin worked:
Use the inAppBrowser plugin and set the target to _system.
cordova.InAppBrowser.open('tel:123456789', '_system');
This by passes the issues I was seeing in iOS with unsupported url, and launches the native system's web browser (i.e., Does not rely on WhiteListPlugin to allow the URL call).
Hope this helps.
Cordova version 6.3.1.

How to access the internet in a cordova ios application?

I'm using HTTP requests to active php files on a server to draw in information from a database. The project works perfectly on the x-code simulator however on the device there seems to be no internet access for the app. My information from the database appears blank. It's as if the http requests aren't running.
Below is my config.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/GearSwipeTutorial" version="1.0.0" viewmodes="maximized">
<tizen:application id="rMZJXG1BgI.GearSwipeTutorial" package="rMZJXG1BgI" required_version="2.2"/>
<content src="index.html"/>
<feature name="http://tizen.org/feature/screen.size.all"/>
<icon src="icon.png"/>
<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
<access origin="http://cs1.ucc.ie" subdomains="true" />
<access origin="http://www.webqr.com" subdomains="true" />
<access origin="http://fonts.googleapis.com/css?family=Raleway" subdomains="true" />
<access origin="http://code.jquery.com" subdomains="true" />
<access origin="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" subdomains="true" />
<access origin="http://fonts.gstatic.com" subdomains="true" />
<access origin="http://maps.gstatic.com/maps-api-v3/api/js/18/4/main.js" subdomains="true" />
<gap:plugin name="org.apache.cordova.network-information" version="0.2.3" />
<gap:plugin name="org.apache.cordova.network-information" /> // Change square braces to arrow braces.
<feature name="NetworkStatus">
<param name="ios-package" value="CDVConnection" />
</feature>
<access origin="*" subdomains="true" />
<plugin name="Camera" value="CDVCamera" />
<plugin name="NetworkStatus" value="CDVConnection" />
It works perfectly in the simulator and browser but not on the device. The function breaks at xmlhttp.onreadystatechange.
function importJson(str) {
alert("1");
if (str=="") {
document.getElementById("top5").innerHTML="";
return;
alert("2");
}
if (window.XMLHttpRequest) {
alert("3");
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
alert("4");
}
xmlhttp.onreadystatechange=function() {
alert("15");
if (xmlhttp.readyState==4 && xmlhttp.status == 200){
alert(xmlhttp.response);
alert("5");
data = JSON.parse(xmlhttp.response);
receivedData(data);
alert("hello");
}
}
I dont thing there is anything specific in the phone gap which allow or disallow the internet access . The most important thing is <access origin="*" subdomains="true" /> and it is in the place for you .
I guess your device connection is too slow and your request in timing out this could be the reason . Try to take device in the same network in which you are trying to access for simulator .
Shouldn't you be using something like XMLHttpRequest
function reqListener () {
console.log(this.responseText);
}
var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.open("get", "yourFile.txt", true);
oReq.send();
You probably need to use generic javascript functions because I don't think that ActiveX objects will work on all devices.
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

Resources