Location Manager was created in the dispatch queue

what does this message mean?

NOTIFICATION. The allocation manager (0xe86bdf0) was created in a send queue running on a thread other than the main thread. The responsibility of the developer is to ensure that a run loop is executed in the stream on which the location manager object is distributed. In particular, the creation of location managers in arbitrary send queues (not tied to the main queue) is not supported and will not result in callbacks.

+5
source share
3 answers

You must create a CLLocationManager in a thread with an active run loop, such as the main thread. You should not create it in the background thread. See the CLLocationManager class reference for more information:

(The configuration of your location manager object should always be done in a thread with an active startup loop, such as the main thread of your applications.)

If you are interested in what a run loop is, see Run Loops for more information.

+10
source

Using Swift 3, the following function will be executed:

OperationQueue.main.addOperation{"your location manager init code"}
+5
source

This means that if you created a location manager in a thread other than the "Main" thread (that is, a thread in which all the user interface code for your application is executed), you always need to call it (ie a location manager) from the thread that created it.

To debug the problem in your code, you can, for example, wrap the creation (and calls) of the location manager inside the send queue for the main thread:

dispatch_sync(dispatch_get_main_queue(),^ {
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
});

and

dispatch_sync(dispatch_get_main_queue(),^ {
  [self.locationManager startUpdatingLocation];
});

Or something similar to see if the error message has disappeared.

+3
source

All Articles