0

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.
Community
  • 1
  • 1
Dimson
  • 99
  • 11
  • Are you sure `[[NSBundle mainBundle] bundleIdentifier]` returns you bundle id? As I remember correctly, it doesn't work with binary-only apps because there is no bundle thus no bundle id. It works with normal applications because they are installed as a bundle. Try passing just some string like `@"com.company.myapp"` as a bundle id. This is what I do when I want to get location in daemon. – creker Dec 03 '13 at 23:52
  • I put Info.plist file near binary, so when I start binary i have bundleId, and status 0. If I remove Info.plist, then I don't have bundleId and status 1. Do you know, is compiler warning about setAuthorizationStatus: Class method '+setAuthorizationStatus:forBundleIdentifier:' not found (return type defaults to 'id') is ok? I didn't declare it anywhere. – Dimson Dec 04 '13 at 05:30
  • Yes, that's normal. Did a quick test - it works for me. Used exact same code as yours and got `kCLAuthorizationStatusAuthorized` as a status. Don't know for `didUpdateLocation` but `location` property does contain location. – creker Dec 04 '13 at 06:46
  • location property does, but latitude and longitude is 0.0. Do you use iOSOpenDev? Can Semitethered jailbreak affect it? Also I think i should add that I'm adding entitlements after build with ldid: ldid -S//entitlements.xml /binary – Dimson Dec 04 '13 at 07:13
  • No, I'm building it as a regular iOS application using just Xcode. "Can Semitethered jailbreak affect it" I don't think so. Check if entitlements are indeed inside the binary using `ldid -e`. Also check the console when you launch your application. Sometimes iOS logs some useful info in there. – creker Dec 04 '13 at 07:58
  • I've updated original post – Dimson Dec 04 '13 at 09:26
  • Console output with Info.plist looks ok. Entitlements are ok because otherwise locationd would log message saying that application lacks entitlement. Unfortunately I don't know why it's not authorizing your application. Try giving your app root permissions. No need to launch it from root user (mobile user works too) just give it root permissions. – creker Dec 05 '13 at 08:06
  • Could you advise me how to do this? I tried with system("echo alpine | su"); but no reaction – Dimson Dec 06 '13 at 09:59
  • `chown root:wheel Saimon` – creker Dec 07 '13 at 13:05
  • Thanks for advice, but same result :( – Dimson Dec 09 '13 at 10:18

2 Answers2

0

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

Registering unknown app identifier com.apple.xcode.dsym.Saimon failed
  • I just put it in directory with binary – Dimson Dec 06 '13 at 04:59
  • That's normal. I see this in my applications too. – creker Dec 06 '13 at 06:51
  • Try if this NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier] returns your Bundle ID or null – user3025315 Dec 07 '13 at 07:23
  • Where do you think `com.apple.xcode.dsym.Saimon` is came from? `[[NSBundle mainBundle] bundleIdentifier]` is not a problem, I already asked about it. This error message is normal. I see it too in my applications but they can authorize themselves and obtain location. – creker Dec 07 '13 at 13:05
  • I have the same issue. I have placed plist with binary but still it says "Launch Services: Registering unknown app identifier 'com.app.magic' failed". Any suggestion will be highly appreciated. – Ahad Khan May 23 '14 at 12:42
0

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.

Dimson
  • 99
  • 11
  • That's very strange. I'm using `setAuthorizationStatus:forBundleIdentifier:` in my daemons to get location. Everything is working on iOS 5-7. For iOS4 I'm using method similar to yours. And I receive location events through `didUpdatedLocations:` method. Doesn't matter it's comand line tool or not. I can only think of one thing. Do you have a running runloop in your apps? Obviously, you won't receive any events without it. And in case of command line tool you have to run it yourself. – creker Jan 15 '14 at 22:16
  • Hi! Yes i have runLoop and I added timer into it that calls `NSLog(@"Coordinates are %f %f %f %f", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy, location.verticalAccuracy);` It gives locations but didUpdateLocations doesn't triggers – Dimson Jan 18 '14 at 15:08
  • Check out my update here http://stackoverflow.com/questions/11086083/get-gps-without-alert-view-with-root-permissionjailbreak – creker Feb 14 '14 at 18:53