I have a query regarding how delegates work. My understanding was that delegates take responsibility for doing 开发者_Go百科certain tasks on behalf of another object.
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
Am I right in thinking that in the example code above that the instance of CLLocationManager is created on a new thread so that it can get on with trying to find the location information it needs. When it completes its task (or encounters an error) it calls-back using the appropriate methods located in self e.g.
locationManager:didUpdateToLocation:fromLocation:
Essentially locationManager
sends messages to self
(which conforms to the correct delegate protocol) when things happen
cheers gary
That is mostly correct.
the instance of CLLocationManager is created on a new thread
No, the instance is created on the thread you call it from. You posted no threading-related code. Of course the Location Manager avoids blocking the thread while working. This may be using a background thread internally, but you don't know or care.
locationManager sends messages to self (which conforms to the correct delegate protocol) when things happen
Yes.
精彩评论