0

I am using CLLocationManager, if the program is installed for the first time, it requires user to accept or deny to share his location. What I want is to program itself to wait until user prompts.

Now the issue is I am waiting there with usleep()

while ([CLLocationManager authorizationStatus] == USER_NOT_PROMPTED) {
    usleep(10000);
}

But this causes the actual iPhone to be locked in a way that the location sharing question does not pop up, therefore the program hangs. Is there a way to run those user prompts in a separate thread? I am using iOS 6.1

Sarp Kaya
  • 3,686
  • 21
  • 64
  • 103
  • No, you cannot access the internal behavior of a library and even if you could, you can't perform UI interaction on a separate thread. You need to rethink your logic instead. If the user accepts, your CLLocationManager will start as usual. If it fails, then you will get the callback `didFailWithError:` – borrrden Jul 29 '13 at 02:58
  • Then it's a good practise to run the entire program in a separate process or thread? – Sarp Kaya Jul 29 '13 at 03:00
  • Your program will have no concept of processes. You need to be more specific because the answer to the above question is "probably not" – borrrden Jul 29 '13 at 03:01
  • Basically, I do not want user to do anything before the location services prompt pops up. – Sarp Kaya Jul 29 '13 at 03:03

1 Answers1

1

Your program is freezing because you're blocking the run loop, which makes it impossible for the system to prompt the user for permission to use location. Don't do that. If you want the user to allow or deny use of their location right away, just make a location manager call early in your app. If you don't want the user to be able to do anything else before they decide, don't give them anything to do -- show a blank screen, perhaps.

That doesn't sound like a good user experience, though, so it'd be better to find a way to let them do as much as possible. Why not just assume that the user is denying you permission to use their location until they've decided otherwise?

Caleb
  • 124,013
  • 19
  • 183
  • 272