2

how can i get gps without alert view (jailbroken iphone) ?

NSString *newText;

CLLocationManager * locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];

CLLocation* location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];

newText = [[NSString alloc] initWithFormat: @"Your Position : %f %f", coordinate.latitude, coordinate.longitude];

NSLog(@"%@", newText);
osmund sadler
  • 1,021
  • 2
  • 15
  • 27

1 Answers1

4
[CLLocationManager setAuthorizationStatus:YES forBundleIdentifier:@"your app bundle identifier"];

To use this your application entitlements should have com.apple.locationd.authorizeapplications key with boolean value set to true.

UPDATE

Found much better solution. Add to your application entitlements com.apple.locationd.preauthorized key with boolean value set to true. This will preauthorize your application so you could request location without any user permission or private APIs. I tested it on iPhone 4S, 5, 5C, 5S with iOS 5-7. It works in daemons or command line tools without any Info.plist, just plain binary.

For the test I used the following code

#import <CoreLocation/CoreLocation.h>

@interface LocationDelegate : NSObject<CLLocationManagerDelegate>
@end

@implementation

-(void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray*)locations
{
    NSLog(@"%@", locations);
}

@end

int main(int argc, char * argv[])
{
    LocationDelegate* delegate = [[LocationDelegate alloc] init];

    CLLocationManager* manager = [[CLLocationManager alloc] init];
    manager.delegate = delegate;
    [manager startUpdatingLocation];

    [[NSRunLoop currentRunLoop] run];

    return 0;
}
creker
  • 9,400
  • 1
  • 30
  • 47
  • ... rembering, of course, to locally declare `+ (void) setAuthorizationStatus: (BOOL)status forBundleIdentifier: (NSString*)id;`, since that's private API. – Nate May 21 '13 at 04:21
  • Well, with the default settings you now get with Xcode / CLang / ARC, [it's no longer a warning](http://stackoverflow.com/a/13486095/119114). It's an **error**, and your project won't build. Even if you are using older tools/settings for your project, it's never a good idea to ignore warnings. It makes it harder to catch other legitimate problems that the compiler finds for you. – Nate May 21 '13 at 20:53
  • @creker I add this record in my plist `com.apple.locationd.authorizeapplications` `` and this code in my project `[CLLocationManager setAuthorizationStatus:YES forBundleIdentifier:@"your app bundle identifier"];` but `[CLLocationManager authorizationStatus]` return `kCLAuthorizationStatusRestricted` – Kmd Aug 22 '13 at 07:57
  • 1
    Instead of "your app bundle identifier" you should put actual bundle ID of your app. Then just check whether you get coordinates, don't look at the status. – creker Aug 22 '13 at 19:54
  • I realized! I have not bundle ID, my app pure cli (command-line non-Cocoa application ), what I should do then? – Kmd Aug 23 '13 at 11:52
  • 1
    It doesn't matter. My apps also just daemons without any GUI. I'm building them with Xcode so I have a valid Info.plist file with bundle ID. This is the bundle ID that I pass to mentioned function. Works perfectly on iOS 5 and 6. – creker Aug 23 '13 at 17:00
  • I have followed the steps but when I install my app it says locationd[44] : Launch Services: Registering unknown app identifier com.app.magic failed ....... locationd[44] : Launch Services: Unable to find app identifier com.app.magic – Ahad Khan May 24 '14 at 07:39
  • I see that too but it doesn't mean app will not receive location updates. You can ignore it. – creker May 24 '14 at 11:19
  • Only "-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status" ......... delegate get called and inside it when I check [CLLocationManager authorizationStatus] it says kCLAuthorizationStatusNotDetermined. Can anyone please tell me where I m lacking. Thanks – Ahad Khan Jun 06 '14 at 11:41
  • Sorry, don't know why it doesn't work for you. It works for me. Here http://stackoverflow.com/questions/21780277/location-not-determined-using-daemon also works. I even found this https://github.com/liuyuning/TestLocation – creker Jun 06 '14 at 12:45
  • Can someone provide a compiled binary of this please? I'd like to use this on my jailbroken iPhone SE's command line. – Frak Nov 07 '19 at 01:36