Get iPhone location in iOS without preference. Location settings are set to ON

I am writing a demon like the Chris Alvares demon . I want the divice location to be in the background without user permission. If the parameter Location Services

in the settings is set to ON

, then I have no problem getting the location. To do this, I add a com.apple.locationd.preauthorized

key with a boolean value set to true to my executable file permissions . The problem is thatLocation Services

switched off. In this case, when I want to get the device's location, a UIAlertView message pops up indicating to the user that location services are disabled. There are basically 2 ways, but I don't know how feasible they are. The first is to programmatically enable / disable the location services settings in the settings. Second, get location using a different code without requiring the installation of location servicesON


Update 01:

I did as iMokhles said and I think it should work but nothing happens. I think this is because of the rights and I saw the syslog and this is what is written:

iPhone locationd[44] <Error>: Entitlement com.apple.locationd.authorizeapplications required to use _CLDaemonSetLocationServicesEnabled
iPhone myDaemon[3443] <Error>: CoreLocation: CLInternalSetLocationServicesEnabled failed

      

So I added this key to permissions, but it still gave me this error. After I checked the permissions for the Settings app, I added these lines to the rights panel, but again nothing happens.

<key>com.apple.locationd.authorizeapplications</key>
<true/>
<key>com.apple.locationd.defaults_access</key>
<true/>
<key>com.apple.locationd.effective_bundle</key>
<true/>
<key>com.apple.locationd.status</key>
<true/>

      

+3


source to share


1 answer


Here is an example from FlipSwitch Location Switch

declare it in the header

@interface CLLocationManager
+ (id)sharedManager;
+ (BOOL)locationServicesEnabled;
+ (void)setLocationServicesEnabled:(BOOL)enabled;
@end

      

Then you can access it using the following code to check if it is included

if([[[objc_getClass("CLLocationManager") sharedManager] locationServicesEnabled] {
    // Enabled
} else {
   // Disabled
}

      

and enable / disable location



[objc_getClass("CLLocationManager") setLocationServicesEnabled:YES];
[objc_getClass("CLLocationManager") setLocationServicesEnabled:NO];

      

and don't forget to import CoreLocation Framework;) and

#import <objc/runtime.h>

      

EDIT Check the code above

Luck

+1


source







All Articles