3

I wrote a little application that gets started as a daemon. It basically will just output the phones GPS location.

the main.m:

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

NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
LocationController *obj = [[LocationController alloc] init];
[obj getLocation];    
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop run];

[p drain];
return 0;
}

the LocationController.m

@implementation LocationController
@synthesize locationManager;

-(id)init {
    self = [super init];
    if(self) {
        trackingGPS = false;
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
    }
    return self;
}

-(void)getLocation {
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation     *)newLocation fromLocation:(CLLocation *)oldLocation {
    NSLog(@"NEW LOCATION :: %@", newLocation);
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"LOCATION ERROR : %@", error);
}

-(void) dealloc {
    [locationManager release];
    [super dealloc];
}
@end

So if I run the application manually off springboard, it works fine and logs the GPS location...at least for 15-20seconds...then springboard terminates the application because it doesn't repsond - an expected behavior.

If I however start the application at startup (launchDaemon), it also starts fine but the delegate function 'didUpdateToLocation' never get's called!!

I'm on iOS 5 so not sure what the problem is. Any help is truly appreciated.

THX !!

Pascal
  • 315
  • 5
  • 22

1 Answers1

1

Instead of calling "startUpdatingLocation", you should use startMonitoringSignificantLocationChanges. Whenever the user's location changes significantly, it will call your app and you will have some time to do some background processing and determine if you want to open your app or not.

You can also have the device call your app if the user enters some region that you wish to monitor.

See this question for further details.

Community
  • 1
  • 1
adamame
  • 188
  • 11
  • hey aguy. Thx for the hint but it still won't work! The delegate function is not called. But I think this is just not possible anymore on iOS 5+ – Pascal Mar 01 '12 at 23:38