Skip to content

Instantly share code, notes, and snippets.

@AppWerft
Created October 23, 2018 11:23
Show Gist options
  • Save AppWerft/1318364a0cb022ea1f96226185e0943e to your computer and use it in GitHub Desktop.
Save AppWerft/1318364a0cb022ea1f96226185e0943e to your computer and use it in GitHub Desktop.
module.exports = function(_win, _onOK, _onDenied) {
function setGPSprecision() {
Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
Ti.Geolocation.distanceFilter = 10;
_onOK();
}
// https://github.com/appcelerator-developer-relations/appc-sample-ti510/blob/master/app/controllers/permissions.js#L188
function checkPermission() {
Log("open event in checkPermissions");
if (!Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE)) {
if (Ti.Geolocation.locationServicesAuthorization == Ti.Geolocation.AUTHORIZATION_DENIED) {
Ti.Platform.openURL(Ti.App.iOS.applicationOpenSettingsURL);
Ti.App.addEventListener('resume', checkPermission);
} else
Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, function(e) {
if (e.success) {
Log('successful geo location permission for iOS');
setGPSprecision();
} else {
var alertDlg = Ti.UI.createAlertDialog({
title : L("GEOLOCATION_DENIED_TITLE"),
message : L("GEOLOCATION_DENIED_MSG"),
buttonNames : [L('DIALOG_OK')],
cancel : 0
});
alertDlg.addEventListener('click', function() {
Ti.Platform.openURL("app-settings:root=LOCATION_SERVICES");
});
};
});
} else {
Log("Permission granted");
setGPSprecision();
}
}
checkPermission();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment