I’ve made a weather application which currently needs to use your location in order to work. I’m busy trying to get that dependency out, but i still need to know at first start if the user will allow it or not, to create a current location managed object to work with.
The idea is that it loads the first few things, then asks for permission if necessary and continues afterwards. It worked at first and i’m not sure what i’ve changed to break it, but i hope some of you can see what is wrong. I’ve been staring myself blind with this for a few hours now, so some fresh view would be appreciated 🙂
For the people reading this for the second time: Yes, i re-wrote the question since the problem seems to be somewhere else than i thought.
My app never gets past this piece of code:
dispatch_sync(dispatch_get_main_queue(), ^{
locationManager = [[CLLocationManager alloc]init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
[locationManager startUpdatingLocation];
});
It’s the first things that happens in my didFinishLaunching method, and i can’t find anything that would be blocking the mainthread. Earlier, i had a similar problem, where i managed to get the authorization from the locationmanager but later on the app stopped at a dispatch on the main queue (to initialize my interface). So why is it being blocked?
Well, your main queue is currently busing executing
application:didFinishLaunchingWithOptions:. Then you come along and ask it to wait (dispatch_sync) until it has executed the location manager block – which it cannot start to do until the main queue is no longer busy. So you’ve got a classical deadlock situation.Why are you using a
dispatch_syncblock here anyway?