0

I call startMonitoringSignificantLocationChanges in location manager init.

I expect that if there is a location event didFinishLaunchingWithOptions will be launched and execute the following code. (including background mode and if app was terminated)

The app freezes (black screen when i try to launch it after a few hours in the background in different location)

Probably i'm doing something wrong when i get a location event. I would appreciate if someone has an idea what's the problem.

By the way, there is no way to simulate this kind of location event but physically move to a different location with different cell tower. is there? ... :(

LocationController.m :

- (id)init
{
    self = [super init];
    if (self != nil) {
        self.locationManager = [[[CLLocationManager alloc] init] autorelease];
        self.locationManager.delegate = self;
        self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
        [self.locationManager startUpdatingLocation];
        [self.locationManager startMonitoringSignificantLocationChanges];
        [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(stop) userInfo:nil repeats:NO];
    }
    return self;
}
appdelegate.m : 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
    if (locationValue)
    {
        [[LocationController sharedInstance] startMonitoringSignificantLocationChanges];
        UIApplication *app  = [UIApplication sharedApplication];
        bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ 
            [app endBackgroundTask:bgTask]; 
            bgTask = UIBackgroundTaskInvalid;
            }];
        [self updateLocationService];
        return YES;
    }
}
- (void) updateLocationService {
    [[LocationController sharedInstance] start];
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(stop) userInfo:nil repeats:NO];    
}
- (void) stop {
    [[LocationController sharedInstance] stop];
}

Thank you!

Liatz
  • 4,997
  • 7
  • 28
  • 33

1 Answers1

2

Your didFinishLaunchingWithOptions: method does not return anything if there is no UIApplicationLaunchOptionsLocationKey set.

Just move the return statement outside your if clause:

if (locationValue)
{ 
    ... 
}
return YES;
user991228
  • 21
  • 2