0

I asked this question a couple days ago about my app not showing up under Settings > Location Services after reinstall. I found out that after reinstalling, I have to run the app and wait for the "Use Current Location" authorization alert view to be displayed for the app to show up under the Location Services list. In turn, I found out that my app doesn't display this alert view instantly when the app is started.

Here's some bits of code that might be the problem:

-(void)restartGps: (UIWebvView *)curWebView {
  [locationManager startMonitoringSignificantLocationChanges];
  [self performSelector:@selector(noGpsLock:) withObject:curWebView afterDelay:GPS_TIMEOUT];
}

-(void)noGpsLock: (UIWebView *)curWebView {
  if (!hasLocationFix) {
    [locationManager stopMonitoringSignificantLocationChanges];
    [self performSelector:@selector(restartGps:) withObject:curWebView afterDelay:GPS_TIMEOUT];
  }
}

hasLocationFix is set to be TRUE when -locationManager:didUpdateToLocation:fromLocation: is called.

I initially call restartGps: in viewDidLoad and let the two methods call each other from then on. I found out that the first time restartGps: is called (from viewDidLoad), the alert didn't appear, therefore the app couldn't get any location. After a noGpsLock: and a restartGps calls, the alert finally appeared and the app was able to get a location.

Why is the alert not showing up the first time restartGps: is called?

4

0 回答 0