CLLocationmanager setAuthorizationStatus doesn't work (jailbreak)

寵の児 提交于 2020-01-03 04:52:04

问题


I have jailbroken device with 6.1.3 iOS. Also I have command-line tool that should give me coordinates. Code that is about location works perfectly with normal application, but not in command line.

I found similar question, but it doesn't seems to work: Get GPS without alert view with ROOT permission(jailbreak)

- (void) start
{
NSLog(@"Started");
if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized)
{
    NSLog(@"%i", [CLLocationManager authorizationStatus]);
}

//[locationManager setAuthorizationStatus:YES forBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]];
[CLLocationManager setAuthorizationStatus:YES forBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]];
NSLog(@"%@", [[NSBundle mainBundle] bundleIdentifier]);
NSLog(@"%@", [[NSBundle mainBundle] bundlePath]);
if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized)
{
    NSLog(@"%i", [CLLocationManager authorizationStatus]);
}

[locationManager startUpdatingLocation];

}

so it always log 0 as authorization status = kCLAuthorizationStatusNotDetermined.

I've also added app entitlements with ldid after building with

com.apple.locationd.authorizeapplications

key set true. also had some experiments with Info.plist, but still

didUpdatedLocation

never triggers.

Thanks in advance!

here is my main if needed:

#import <Foundation/Foundation.h>
#import "locateClass.h"

int main (int argc, const char * argv[])
{

    @autoreleasepool
    {   
        // insert code here...
        NSLog(@"Hello, World!");
        locateClass *loc = [[locateClass alloc] init];
        [loc start];
    }
    return 0;
}

Also I'm using iOSOpenDev

UPDATE:

If I don't use Info.plist, With this code I have this in Console:

iPhone-AppServer Saimon[841] <Warning>: Hello, World!
iPhone-AppServer Saimon[841] <Warning>: Started
iPhone-AppServer Saimon[841] <Warning>: 1
iPhone-AppServer Saimon[841] <Warning>: (null)
iPhone-AppServer Saimon[841] <Warning>: /private/var/mobile/docs/fromMac/Debug-iphoneos
iPhone-AppServer Saimon[841] <Warning>: 1
iPhone-AppServer awdd[842] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
iPhone-AppServer awdd[842] <Error>: CoreLocation: CLClient is deprecated. Will be obsolete soon.

If I do - such output:

iPhone-AppServer Saimon[854] <Warning>: Hello, World!
iPhone-AppServer Saimon[854] <Warning>: Started
iPhone-AppServer locationd[362] <Warning>: Launch Services: Registering unknown app identifier com.apple.xcode.dsym.Saimon failed
iPhone-AppServer locationd[362] <Warning>: Launch Services: Unable to find app identifier com.apple.xcode.dsym.Saimon
iPhone-AppServer Saimon[854] <Warning>: 0
iPhone-AppServer Saimon[854] <Warning>: com.apple.xcode.dsym.Saimon
iPhone-AppServer Saimon[854] <Warning>: /private/var/mobile/docs/fromMac/Debug-iphoneos
iPhone-AppServer Saimon[854] <Warning>: 0
iPhone-AppServer awdd[855] <Error>: libMobileGestalt copySystemVersionDictionaryValue: Could not lookup ReleaseType from system version dictionary
iPhone-AppServer awdd[855] <Error>: CoreLocation: CLClient is deprecated. Will be obsolete soon.

回答1:


How do you load info.plist? because it returns failed...

Registering unknown app identifier com.apple.xcode.dsym.Saimon failed



回答2:


Well I found not so easy workaround.

Step-by-step.

To authorize yourself you shuld stop locationd process, but killall -9 locationd won't help you. to stop it: launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist

Then edit /var/root/Library/Caches/locationd/clients.plist file on this way:

Root
    |__<your_bundleid> (Dictionary)
        |__Whitelisted (Boolean)  -  NO
        |__BundleId (String)  -  <yourBundleID>
        |__Authorized (Boolean)  -  YES
        |__Executable (String)  -  <path_to_your_binary>
        |__Registered (String)  -  <path_to_your_binary>

And then start locationd:

launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist

After this it is possible to get the location, but in comand line tool didUpdatedLocations method doesn't trigger, and one more problem: after about a minute you [CLLocationManager AuthenticationStatus] will give you Denied status, so you need manually edit plist again and delete TimeMissing key from your bundleid dictionary.

Here's the code worked for me after self registration:

while (1){
    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];

    CLLocation *location = locationManager.location;

    if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorized)
    {
        NSLog(@"%i", [CLLocationManager authorizationStatus]);
        if( [CLLocationManager authorizationStatus] == 2)
        {
            system("ps ax | grep locationd");
            system("launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist");
            NSString* plistPath = [[NSString alloc] initWithString:@"/var/root/Library/Caches/locationd/clients.plist"];
            NSMutableDictionary* plist = [NSMutableDictionary dictionaryWithContentsOfFile: plistPath];
            NSMutableDictionary *myBundle = [plist objectForKey:[[NSBundle mainBundle] bundleIdentifier]];
            [myBundle removeObjectForKey:@"TimeMissing"];
            NSLog(@"Relaunching");
            [plist setObject:myBundle forKey:[[NSBundle mainBundle] bundleIdentifier]];
            [plist writeToFile:@"/var/root/Library/Caches/locationd/clients.plist" atomically:YES];
            system("launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist");
        }

    }

    NSLog(@"Coordinates are %f %f %f %f",
          location.coordinate.latitude,
          location.coordinate.longitude,
          location.horizontalAccuracy,
          location.verticalAccuracy);

    if ( location.coordinate.latitude == 0 && location.coordinate.longitude == 0)
    {
        NSLog(@"Nulss");
        system("launchctl unload /System/Library/LaunchDaemons/com.apple.locationd.plist");
        system("launchctl load /System/Library/LaunchDaemons/com.apple.locationd.plist");
    }
    else
    {
        NSLog(@"Got IT");
        //[locationManager stopUpdatingLocation];
        //break;
    }
    sleep(10);
}

Tested on iOS6 and iOS7.



来源:https://stackoverflow.com/questions/20362565/cllocationmanager-setauthorizationstatus-doesnt-work-jailbreak

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!