dpa99c / cordova-plugin-request-location-accuracy

Cordova/Phonegap plugin for Android and iOS to request enabling/changing of Location Services by triggering a native dialog
96 stars 62 forks source link

[Question] Accessing location settings on iOS #63

Closed RamiAhmed closed 5 years ago

RamiAhmed commented 5 years ago

Hi!

Great plugin.

I was wondering how you managed to open the settings page from within the app on iOS. According to: https://www.zerotoappstore.com/how-to-open-settings-in-ios-programmatically.html - it sounds like Apple does not allow opening up any specific settings pages programmatically.

We are working on a cross-platform app for iOS and Android, and we would like to help the user by providing easy buttons for opening certain settings (e.g. geolocation or Wifi maybe).

I was looking at this method:

// Plugin API
- (void) request:(CDVInvokedUrlCommand*)command;{
    CDVPluginResult* pluginResult;
    @try {
        if (__locationStarted) {
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Location is already being requested"];
        }else if(![self canRequest]){
            // Location services is already enabled
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
        }else{
            [self.locationManager startUpdatingLocation];
            __locationStarted = YES;
            pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
        }
    }@catch (NSException *exception) {
        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:exception.reason];
    }
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

But it is unclear to me (since I don't know the programming language) how a certain setting page is requested.

We have found ways to do this programmatically (e.g. with prefs:root=LOCATION_SERVICES), but we don't want our app to be rejected by Apple for obvious reasons.

Could anyone perhaps enlighten me on this topic if you have the time?

Thanks in advance.

dpa99c commented 5 years ago

This plugin doesn't directly open the Location Settings page but it indirectly invokes a native iOS system dialog by requesting that the native location manager start updating locations ([self.locationManager startUpdatingLocation]). If Location Services is switched off and an app asks for location updates, then the in-built behaviour of iOS is to show that system dialog with the "Settings" button which, upon the user pressing it, directly opens the Privacy page in the Settings app which contains the switch to turn Location Services ON. All of this uses API calls sanctioned by Apple so is fine to include in App Store releases. I hope this clarifies the approach taken by this plugin for you.

RamiAhmed commented 5 years ago

Hi @dpa99c - Thanks for the answer, it definitely clarified things for us. Appreciate you taking the time to respond so thoroughly.