phonegap oauthio plugin wont load - ios

Im testing the phone gap oauthio plugin but cannot get it to work
followed the docs.
added the plugin with the command line
and also installed inappbrowser
also added this to my config.xml
<gap:plugin name="org.apache.cordova.inappbrowser" />
<gap:plugin name="com.phonegap.plugins.oauthio" />
the inappbrowser its loaded and working.
but the OAUTH is not.
i added some alert() here and there
but when i add an alert to display the content o OAUTH it won't happen
alert('device ready'); //to see if the device is ready, no problems here
alert(window.open); //to see if inbrowserapp is loaded, no problems here
alert(OAuth);// no message. looks like is not defined,also tried alert(OAuth.initialize) same luck
OAuth.initialize("VeQmyEu0QtzIOO9WjM1IlAU0ty4");
alert('postinit');
inside the plugin the definition says "OAuth" so the name is ok and my installed plugins are
oauthio-test % phonegap plugin list
[phonegap] com.phonegap.plugins.oauthio
[phonegap] org.apache.cordova.inappbrowser
i also delete the contents of "platform/ios" to prevent file caching
my access are these
<access origin="*" />
<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
<access origin="*graph.facebook.com*" />
<access origin="*api.twitter.com*" />
<access origin="*github.com*" />
no luck so far.
it felts like when I debuged in IE6
EDIT:
Added the full code that shows that im inside an event 'ondeviceready'
$(document).on('deviceready', function() {
alert('device ready');//shows ok
alert(window.open); //shows ok
alert(OAuth.OAuth.initialize);//it dies here
OAuth.initialize("VeQmyEu0QtzIOO9WjM1IlAU0ty4");
alert('postinit');//this alert won't displayed
$('#fb-connect').on('click', function() {
$('#result').html("");
OAuth.popup("facebook", function(e,r) {
if (e)
$('#result').html('error: ' + e.message);
else
// the access_token is available via r.access_token
// but the http functions automagically wrap the jquery calls
r.get('/me').done(function(data) {
$('#result').html("facebook: Hello, " + data.name + " !");
});
});
});

in terminal you need to past this url and enter
"phonegap plugin add https://github.com/oauth-io/oauth-phonegap ".
and you can use android or iOS simulator to run the application.

ok. so looks like it's a phone gap bug.
If you add a plugin later you need to clean up your platform and plugins/*.json files
I followed this post and the plugins were builded and installed correctly
Phonegap 3.0 IOS plugins not found

Related

InAppBrowser does not open properly with iOS 10.2 (Xcode 8)

I've been using the cordova-plugin-inappbrowser plugin for a long time now and when I updated the software to 10.2.1 on my apple test devices the plugin no longs works properly. When I try to open the inappbrowser link nothings happens unless I click the home button and return to the app. This happens for the simulators as well as on real devices like ipad, iphone 5s, iphone 6 and iphone 7. it works fine on android devices just not the latest iOS.
Here's a list of everything i tried:
updated inappbrowser to latest version - 1.7.1
removed and reinstalled the plugin and ios platform
tried making a blank app with the inappbrowser plugin
tried changing the index.html meta tag to include gap:
<meta http-equiv="Content-Security-Policy" content="default-src * &apos;self&apos; gap: ; script-src &apos;self&apos; &apos;unsafe-inline&apos; &apos;unsafe-eval&apos; *; style-src &apos;self&apos; &apos;unsafe-inline&apos; *; child-src &apos;self&apos; &apos;unsafe-inline&apos; *;">
I can't seem to find anything else to try as most posts I do find that have a similar issue haven't been answered.
Below is the relevant code to how the inappbrowser plugin was installed and is being used:
config.xml Structure
<widget>
<content src="index.html"/>
<access origin="*"/>
<allow-navigation href="*"/>
<preference/>
...
<feature name="StatusBar">
...
</feature>
<platform name="ios">
... icons and splash ...
</platform>
<plugin name="cordova-plugin-inappbrowser" spec="~1.7.1"/>
</widget>
Using plugin in Controller
$scope.showLink = function(url){
var options = {
location: 'yes'
}
$cordovaInAppBrowser.open(url, '_blank', options)
.then(function(event){
// success
console.log('inappbrowser', event);
})
.catch (function(event) {
// error
console.log('inappbrowser error', event);
});
};
$scope.openUrl = function(url) {
window.open(url, '_blank', 'location=no');
};
I'm using ionic v1.7.14 , cordova: 6.2.0 and xcode 8
As suggested by CodeGems, in the comments, adding gap://ready to your Content-Security-Policy should fix the issue.

Ionic2 phone call doesnt work on ios but on android (emu and devices)

In my HTML file I am using a sliding-item and inside the options a button that calls a function:
<button secondary *ngIf="post.telefone" (click)="callIT('tel:'+post.telefone)">
<ion-icon name="call"></ion-icon>
Call
</button>
In the js file I have the function callIt() like:
callIT(passedNumber) {
window.location = passedNumber;
}
In my config.xml I added these line of code:
<access origin="*"/>
<access origin="tel:*" launch-external="yes"/>
This is working for android for both the emulator and on a device. In ios the call functionality isn`t working at all. Thanks to all for help

Cordova/Phonegap Build geolocation on iOS timeout

I have been experiencing the same issue, and have tried in the past 2 weeks numerous solutions found online for this with no success, any help appreciated :)
I am writing a simple app using Cordova for IOS and Android and building it using Phonegap build. The problem is that I cannot get the "navigator.geolocation.getCurrentPosition" (or navigator.geolocation.watchPosition) calls to return anything except a timeout error on iOS. (works perfectly on Android)
Additionally, the location services dialog never appears (requesting user permission to allow GPS for the app)
To add to this strange behavior, it seems that i have to touch the screen after the app is loaded to initiate the geolocation call, on most cases the app just sits there and does nothing until the screen is touched.
Testing this on iPhone 5 with iOS 9
Things I tried:
Changing timeout settings (up to 30 seconds)
Setting enableHighAccuracy true/false
Running code with or without the geolocation plugin
Manually adding the NSLocationWhenInUseUsageDescription/NSLocationAlwaysUsageDescription settings (or both) to the plist file
Installing different plugin versions for the geolocation plugin
Changing Content Security Policy meta tag
Trying to add or remove the <plugin> declaration from root config.xml
Current plugins installed ($cordova plugin list):
cordova-plugin-dialogs 1.2.0 "Notification"
cordova-plugin-geolocation 1.0.1 "Geolocation"
cordova-plugin-whitelist 1.2.0 "Whitelist"
cordova.plugins.diagnostic 2.3.5 "Diagnostic"
Root config.xml:
<?xml version='1.0' encoding='utf-8'?>
<widget id="info.test" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>App name</name>
<description>
App Name
</description>
<author email="test#test.com" href="http://test.com">
App Team
</author>
<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>
</widget>
index.js
var geo = {
getGeo: function() {
navigator.geolocation.getCurrentPosition(
geo.onSuccess,
geo.onError,
{maximumAge:0, timeout: 5000, enableHighAccuracy: false});
},
onSuccess: function(position) {
alert('GOT location');
alert(position.coords.latitude + ' --- ' + position.coords.longitude);
},
onError: function(error) {
alert('error getting geo!');
}
};
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
geo.getGeo();
}
};
app.initialize();
iOS Plist file:
<key>NSLocationAlwaysUsageDescription</key>
<string>This app requires constant access to your location in order to track your position, even when the screen is off.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string/>
Index.html:
<html>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
Some notes:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
Any help in the right direction appreciated!
#daddio
Oh. that's it. I should be more dogmatic on this. This should take care of the problem.
It is not advisable to use Phonegap CLI to make your Phonegap Build build project. Phonegap build requires that index.html and config.xml both sit in the root directory. All the extra files that you are required to use with Phonegap CLI, never are created or needed with Phonegap Build.
So, I'm going to give you one of my working demos. Notice that all the files are in one (1) directory.
tutorial/blog entry - An HTML Boilerplate for Phonegap Build
source code Phonegap--Generic-Boilerplate
Notice how the compiler version is set to:
<preference name="phonegap-version" value="cli-5.2.0" />
Notice, if you change cli-5.2.0 to 3.7.0, nothing appears to change.
Basically for Phonegap Build, you need index.html and config.xml - that's it. Then for security reasons (as of Cordova Tools 5.0.0), it is advisable to create a css file and a javascript file. However, I'll show you how to get around this.
Here is my complete list of Demo Apps.
Phonegap Demo Apps
YOUR FIX
This is my working code, test with 3.5.0 and cli-5.1.1 and cli5.2.0
source code Phonegap-GPS-Test
On Your fix, notice how the version is set to: <preference name="phonegap-version" value="3.5.0" />
Okay, I trust all of this will work for you. As such, your documentation is here:
https://build.phonegap.com/docs
There are some special rules for adding plugins, but I'll give you those when your program is running.
How to add Plugins with Phonegap Build
FOR THE MOST IMMEDIATE FUTURE, get your *core* plugins from this list:
http://cordova.apache.org/docs/en/5.4.0/cordova/plugins/pluginapis.html
Get your 3rd-party plugin from this source:
http://cordova.apache.org/plugins/
When using Phonegap Build, sometimes the pluins get fixed (or updated) and this breaks Phonegap Build. This is because the "fixes" require the latest version of the compiler, and Phonegap Build is always at least one version behind.
There are two ways to deal with 3; see 4 and 5.
I have created this Worksheet. You may want to make a copy or just use it as a reference. I use this worksheet to create my demos, I so know the list is good. I am working on cli-5.2.0 right now. (Should finish by Monday or so.) However, I do not test ALL 3rd-party plugins; there are 800+ plugins.
If you fail to set the version number on a plugin, you will get the latest version. If your build fails, then set the version. If the build still fails, try the previous two or three version to find one that works. NOTE, these older plugins may have bugs that prevent you from using them. So, try an even earlier version.
Lastly, if you think you have hit a bug, then here is a page with links to the Bug respository for each plugin. Last Update is on the top left. Best of Luck.

navigator.notification.alert not working in cordova for ios

I'm working with cordova framework in iphone....Now,i want to use navigator.notification.alertthis function.but,i can not use this function..
I've done this following steps.
step 1: In config.xml file
<feature name="Notification">
<param name="ios-package" value="CDVNotification" />
</feature>
<header-file src="CDVNotification.h" />
<source-file src="CDVNotification.m" />
<resource-file src="CDVNotification.bundle" />
<framework src="AudioToolbox.framework" weak="true" />
step 2 : I've added AudioToolbox.framework in my project
step 3 : added CDVNotification.h and .m file in plugins folder.
step 4: added notification.js into index.html file.
step 5: then finally,i've done this code
document.addEventListener("deviceready", onDeviceReady, true);
function onDeviceReady() {
alert("onDeviceReady");
navigator.notification.alert('Mesage',
null,
'Title',
'OK')
}
can anyone help me!!!
You have to add the plugin using the CLI
use this command
cordova plugin add org.apache.cordova.dialogs
alternatively solution
window.alert();
This global alert. very easy to manage.don't need to added any plugin or anything esle.
I had this problem and couldn't solve it but then it him me since Cordova is nothing but a webview based app javascript based solutions will work as well. So I used this js alert plugin called alertify which is beautiful and customizable as to headers,colors etc. and does the job well.
Javascript Alert Plugiy.

Blackberry webworks background page not working

I am studying blackberry webworks. I have done one demo, where there is one page that run in background and is loaded on device startup. I have used blackberry rim:background to specify background, and has started interval in background page, but the page is not working. Please help me in getting out of this problem,
Here is my code in config.xml
<content src="index.html" >
<rim:background src="index.html" runOnStartup="true" charset="string" />
</content>
And HTML code
Insert title here
<script type="text/javascript" src="timer.js" />
<script>
function background()
{
self.setInterval(interval,"3000");
}
function interval()
{
i=i+10;
}
}
</script>
<body onload=" background()" >
</body>
</html>
Thanks in advance!
which phone/OS are you looking to target with this sample? The background element of the config.xml is a little bit different for a BB10 app, than it is for OS 5-7.
For BB OS 5-7 you would do this just like you have above
<content src="index.html"><rim:background src="listener.html" runOnStartup="true" /></content>
I would check-out the sample config.xml documents over here, and make sure everything is setup properly to start with.

Resources