Location permission alert on iPhone with PhoneGap and ionic - ios

This is a follow up from:
Location permission alert on iPhone with PhoneGap
image: http://imgur.com/c2KBqbm
None of the answers there worked and I am still getting the
"/private/var ... would like to use your location" message.
I have $cordovaGeolocation in a factory
.factory('$cordovaGeolocation', ['$q', 'geo', function ($q) {
return {
getCurrentPosition: function (options) {
var q = $q.defer();
navigator.geolocation.getCurrentPosition(function (result) {
q.resolve(result);
console.log(JSON.stringify(q.resolve(result)));
}, function (err) {
q.reject(err);
}, options);
return q.promise;
},
watchPosition: function (options) {
var q = $q.defer();
var watchID = navigator.geolocation.watchPosition(function (result) {
q.notify(result);
}, function (err) {
q.reject(err);
}, options);
q.promise.cancel = function () {
navigator.geolocation.clearWatch(watchID);
};
q.promise.clearWatch = function (id) {
navigator.geolocation.clearWatch(id || watchID);
};
q.promise.watchID = watchID;
return q.promise;
},
clearWatch: function (watchID) {
return navigator.geolocation.clearWatch(watchID);
}
};
}])
and call it in a resolve in my .state
resolve : {
initialGeo: function ($cordovaGeolocation) {
var posOptions = {timeout: 1000, enableHighAccuracy: true};
return $cordovaGeolocation.getCurrentPosition(posOptions);
}
}
I cannot get rid of this awful message. I'm using the latest ionic and cordova versions with the plain 'ol phonegap geolocation plugin.
What I've tried:
- Changes to the config.xml
<feature name="Geolocation">
<param name="ios-package" value="CDVLocation" />
</feature>
<plugins>
<plugin name="Device" value="CDVDevice" />
<plugin name="Logger" value="CDVLogger" />
<plugin name="Compass" value="CDVLocation" />
<plugin name="NetworkStatus" value="CDVConnection" />
<plugin name="Debug Console" value="CDVDebugConsole" />
<plugin name="Geolocation" value="CDVLocation" />
<plugin name="SplashScreen" value="CDVSplashScreen" />
<plugin name="Battery" value="CDVBattery" />
<plugin name="Globalization" value="CDVGlobalization" />
</plugins>
Ripping out the factory and just doing
document.addEventListener("deviceready", function(){
navigator.geolocation.getCurrentPosition(onsuccess, onerror, params);
}, false);
Moving cordova.js to the first script to be loaded.
Move all js files to root.
The normal permission alert shows once. The ugly one shows 2-3 times and then doesn't show again.
Any help would be greatly appreciated.

I figured it out. If you're asking for geolocation immediately, adding a delay to the route fixed it for me.
resolve : {
waitOnMe: function ( $timeout) {
return $timeout(function () { }, 100);
}
}

Related

Problem with implementation of RTCMultiConnection (stream Audio) in Ionic 3.9.2 IOS version

I have a problem with the implementation of RTCMultiConnection (stream Audio) in Ionic 3.9.2. Unlike the Android version, where everything works fine, the IOS application works only one way - when user connects to an existing stream app receives audio sounds from it. If user starts new stream, nothing is working, even popup asking for permissions to the microphone is missing. The terminal does not display any errors. Has anyone of you faced such a problem?
I've also implemented this plugin
https://github.com/BasqueVoIPMafia/cordova-plugin-iosrtc/blob/master/docs/Building.md
[index.html]
<body>
<script src="https://rtcmulticonnection.herokuapp.com/dist/RTCMultiConnection.min.js"></script>
<script src="https://rtcmulticonnection.herokuapp.com/socket.io/socket.io.js"></script>
<script>
document.addEventListener("deviceready", function() {
if ((typeof device !== "undefined") && device.platform == 'iOS'){
cordova.plugins.iosrtc.registerGlobals();
}
}, false);
</script>
</body>
[home.ts]
constructor(public navCtrl: NavController, private platform: Platform) {
}
clickBtn(){
this.requestPermissions().then(() => {
this.createConnection();
});
}
createConnection() {
const RTCMultiConnection = window['RTCMultiConnection'];
const connection = new RTCMultiConnection();
connection.socketURL = 'https://apilink:9001/';
connection.socketMessageEvent = 'RTC-audio';
connection.session = {audio: true, video: false, oneway: true};
connection.bandwidth = {audio: 64};
connection.sdpConstraints.mandatory = {OfferToReceiveAudio: true,OfferToReceiveVideo: false};
connection.iceServers.push({
urls: 'turn:217.182.77.219:3478',
credential: 'credential_password',
username: 'rtc_username'
});
connection.onPeerStateChanged = this.onPeerStateChanged;
connection.onleave = this.onleave;
connection.onstream = this.onstream;
connection.onstreamended = this.onstreamended;
connection.onRoomFull = this.onRoomFull;
connection.onMediaError = this.onMediaError;
connection.openOrJoin('Channel12345');
}
onPeerStateChanged = event => {
console.log('onPeerStateChanged', event);
}
onleave = event => {
console.log('onleave', event);
}
onstream = event => {
console.log('onstream', event);
}
onstreamended = event => {
console.log('onstreamended', event);
}
onRoomFull = event => {
console.log('onRoomFull', event);
}
onMediaError = event => {
console.log('onMediaError', event);
}
requestPermissions() {
if(!this.platform.is('cordova'))
return Promise.reject('not cordova');
if (this.platform.is('android')) {
return this.requestAndroidPermissions();
}
else if (this.platform.is('ios')) {
console.log("PLATFORM IOS")
return Promise.resolve(true)
}
}
requestAndroidPermissions() {
return new Promise((resolve, reject) => {
const {permissions} = window['cordova'].plugins;
permissions.requestPermissions([
permissions.CAMERA,
permissions.MICROPHONE,
permissions.MODIFY_AUDIO_SETTINGS,
permissions.RECORD_AUDIO,
permissions.ACCESS_NETWORK_STATE,
permissions.ACCESS_WIFI_STATE
],
ok => resolve(ok),
error => reject(error)
);
})
}
}
config.xml
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="*" />
<allow-intent href="itms-apps:*" />
<hook src="hooks/iosrtc-swift-support.js" type="after_platform_add" />
<preference name="ios-XCBuildConfiguration-ENABLE_BITCODE" value="NO" />
<config-file parent="NSMicrophoneUsageDescription" target="*-Info.plist">
<string>App uses your microphone to make calls.</string>
</config-file>
<config-file parent="NSCameraUsageDescription" target="*-Info.plist">
<string>App uses your camera to make video calls.</string>
</config-file>
...
</platform>
I want to add ability to start new stream on IOS, because now it's not working.

Custom ionic/cordva plugin for iOS. Method not defined in plugin error

I am writing my custom plugin in ionic for iOS in swift but I get the following error:
ERROR: Method 'initialize:' not defined in Plugin 'RabbitMqPlugin'
I have searched in order to find solution but I could not figure out what is the problem.
Below is my code.
plugin.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-rabbitmq"
version="0.0.1">
<name>RabbitMqPlugin</name>
<js-module src="www/plugin.js" name="RabbitMqPlugin">
<clobbers target="RabbitMqPlugin" />
</js-module>
<!-- ios -->
<dependency id="cordova-plugin-cocoapod-support" />
<dependency id="cordova-plugin-add-swift-support" />
<platform name="ios">
<pods-config ios-min-version="9.0" use-frameworks="true">
</pods-config>
<pod name="RMQClient" />
<config-file target="config.xml" parent="/*">
<feature name="RabbitMqPlugin">
<param name="ios-package" value="CDVDevice"/>
</feature>
</config-file>
<source-file src="src/ios/CDVHttpRequest.swift" />
<source-file src="src/ios/CDVRabbitMq.swift" />
<source-file src="src/ios/CDVRabbitMqPlugin.swift" />
</platform>
</plugin>
plugin.js file in www folder:
var exec = require('cordova/exec');
var PLUGIN_NAME = 'RabbitMqPlugin';
var RabbitMqPlugin = {
initialize: function(phrase, cb) {
exec(cb, null, PLUGIN_NAME, 'initialize', [phrase]);
}
};
module.exports = RabbitMqPlugin;
CDVRabbitMqPlugin.swift file in src/ios folder:
import Foundation
#objc(RabbitMqPlugin) class RabbitMqPlugin : CDVPlugin {
var mRabbit:rabbitMQ!;
#objc(initialize:)
func initialize(_ command: CDVInvokedUrlCommand){
var pluginResult = CDVPluginResult(
status: CDVCommandStatus_ERROR
);
let token = command.arguments[0] as! String;
if (token.characters.count > 0) {
mRabbit = rabbitMQ(mToken: token);
pluginResult = CDVPluginResult(
status: CDVCommandStatus_ERROR
);
}
self.commandDelegate!.send(
pluginResult,
callbackId: command.callbackId
)
}
}
I have installed the cordova-plugin-add-swift-support module in order to support swift.
I have added custom plugin ionic plugin for Android and I implemented to my ionic project successfully.
Hope you can help me. Thank you
Your feature in the plugin.xml is wrong, it should be
<feature name="RabbitMqPlugin">
<param name="ios-package" value="RabbitMqPlugin"/>
</feature>
Also, if you are not naming the classes with CDVClassname, don't name the files that contain those classes starting with CDV, not sure if that will fail in Swift, but better name the Swift files with the same name the class they contain

Getting Geolocation working with JQM/phone gap

I have an application using phonegap and jQM. i'm trying to get my geolocation to work when clicking the button but i get an error in the console saying geolocation is not defined.
The error is pointing to the onclick="getLocation()". Can anyone help me please?
Heres an example of my code:
<div data-role="page" id="geo" data-add-back-btn="true" onload="onBodyLoad()">
<header data-role="header" data-position="fixed">
<h1>Geolocation</h1>
</header>
<div data-role="content">
<button data-role="button" onclick="getLocation()">Click to get your current position</button>
<div id="mapholder"></div>
</div>
</div>
$("#geo").on('pageinit', function () {
console.log("Geo page loaded!");
function onBodyLoad(){
document.getElementById('geolocation').empty();
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady(){
phoneGapReady.innerHTML = ("")
}
var x=document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition,showError);
}else {
x.innerHTML="Your Browser does not support Geolocation.";}
}
function showPosition(position) {
lat=position.coords.latitude;
lon=position.coords.longitude;
latlon=new google.maps.LatLng(lat, lon);
mapholder=document.getElementById('mapholder')
mapholder.style.height='250px';
mapholder.style.width='100%';
var myOptions= {
center:latlon,zoom:14,
mapTypeId:google.maps.MapTypeId.ROADMAP,
mapTypeControl:false,
navigationControlOptions:
{style:google.maps.NavigationControlStyle.SMALL}
};
var map = new
google.maps.Map(document.getElementById("mapholder"),myOptions);
var marker=new
google.maps.Marker({position:latlon,map:map,title:"Your Location."});
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML="User did not allow Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="Location Data is not Available."
break;
case error.TIMEOUT:
x.innerHTML="Request Timed Out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML="Unknown Error."
break;
}
}
});
Assuming you're using Phonegap 3.x, make sure you've added the geolocation plugin to your project:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
Make sure the config.xml includes it:
<feature name="Geolocation">
<param name="android-package" value="org.apache.cordova.GeoBroker" />
</feature>
Make sure you allow access in the android manifest:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
Try changing
if (navigator.geolocation) {
to
if (typeof(navigator.geolocation) != "undefined") {

Inappbrowser not loading

Im using Phonegap 2.9.0 in ios, i have gone through the tutorial for inappbrowser .and i have tried the following to in my application
App.js Calling method
indexpnl.element.on({
tap: function (e) {
var el = Ext.get(e.target);
var bval = el.getId();
if (bval == "btnfacebook") {
// onDeviceReady()//using this application screen its self loading the site view not in inappbrowser
document.addEventListener("deviceready",onDeviceReady, false);//here nothing happening
}
}
});
jsfunction.js Method
function onDeviceReady()
{
var ref = window.open('http://www.facebook.com', '_blank', 'location=yes');
ref.addEventListener('loadstart', function() { alert('start: ' + event.url); });
ref.addEventListener('loadstop', function() { alert('stop: ' + event.url); });
ref.addEventListener('exit', function() { alert(event.type); });
}
And i have include the plug in config.xml
<feature name="InAppBrowser">
<param name="ios-package" value="CDVInAppBrowser" />
</feature>
When i call using the above method nothing happens.When i call On onDeviceReady() the site is loading in application itslef but not in the inapp browser.What wrong with my code
Dunno but have you checked you have a
<script src="phonegap.js"></script>
in your script as in
https://build.phonegap.com/docs/plugins-using
Leaving it out can produce those kind of errors

Resetting plugins while URL call

When i try to call the url in my phone-gap 2.9.0 application in ios,The application become blank and url loading not in inappbrowser.
Here the code
Config.xml
<feature name="InAppBrowser">
<param name="ios-package" value="CDVInAppBrowser" />
</feature>
Method
var indexpnl = Ext.create('Ext.Panel', {
id: 'indexpnl',
scrollable:'vertical',
height: '100%',
width: '100%',
html:'<div align="center" ><img src="resources/img/img1.png" height="280px" width="100%" /><br><div style="padding:10px;" align="center"><img id="btnlogin" src="resources/img/buttonlogin.png" height="42px" width="100%" /><br><img src="resources/img/buttonfacebook.png" id="btnfacebook" height="42px" width="100%"/><br><div align="center">or</div><img src="resources/img/buttonsignup.png" id="register" height="42px" width="100%"/></div></div>'
});
indexpnl.element.on({
tap: function (e) {
var el = Ext.get(e.target);
var bval = el.getId();
if (bval == "btnlogin") {
goLogin()
}
if (bval == "btnfacebook")
{
var ref = window.open('http://www.facebook.com', '_blank', 'location=yes');
ref.addEventListener('loadstart', function() { alert('start: ' + event.url); });
ref.addEventListener('loadstop', function() { alert('stop: ' + event.url); });
ref.addEventListener('exit', function() { alert(event.type); });
}
if (bval == "register") {
register()
}
}
});
And the NSLOG return
[3475:c07] Resetting plugins due to page load.
How to call the URL in inappbrowser.PLease help me to solve

Resources