Search code examples
ios8titaniumtitanium-mobile

Titanium: Open Privacy -> Location Services programmatically


the following code is able to successfully launch my App's settings programmatically (iOS 8) in Titanium:

var settingsURL = Ti.App.iOS.applicationOpenSettingsURL;
if (Ti.Platform.canOpenURL(settingsURL)) {
  Ti.Platform.openURL(settingsURL);
}

The problem is that if a user has turned off their Location Services inside the Privacy page he/she won't be allowed to change this inside the App's settings, requiring the user to go back into Settings -> Privacy -> Location Services. This is very bad for the user experience-wise.

I know it is possible to launch the Privacy -> Location Services directly, since many apps do, like: Hotel Tonight, Foursquare, Dojo, etc.

How to do this in Titanium?

My configs: SDK 3.5.1GA & iOS8.


Solution

  • For this to work you need to try to create a listener to Titanium.Geolocation, something like:

    Titanium.Geolocation.addEventListener('location', locationCallback);
    

    Keep in mind you need to do this even without checking that you have permission, this way iOS will prompt you to turn on location services using an alert dialog and thus you can be redirected directly to Privacy->Location Services.