2
J'essaye actuellement d'implémenter une fonction de délai d'attente sur un appel de délégué CLLocationManager
. Voici le code:CLLocationManager didUpdateToLocation: sur quel thread?
- (void)checkInAt:(UALocation *)location timeout:(NSTimeInterval)timeout {
NSDate *tickDate = [NSDate dateWithTimeIntervalSinceNow:timeout];
self.locationManager = [[CLLocationManager alloc] init];
self.timeout = [[NSTimer alloc] initWithFireDate:tickDate interval:0 target:self selector:@selector(timedOut:) userInfo:nil repeats:NO];
[self.locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
@synchronized (self.timeout) {
// Todo what if the timer fires right now?
// Is it even feasible? On what thread is CLLocationManager operating?
if (self.timeout.isValid) {
[self.timeout invalidate];
}
else {
// Timed out
return;
}
}
[manager stopUpdatingLocation];
// Do the actual check in
}
- (void)timedOut:(NSTimer *)timer {
@synchronized (timer) {
if (!timer.isValid) {
return;
}
}
}
Si vous lisez le code, vous avez probablement trébuché sur mes questions déjà.
- Existe-t-il un meilleur moyen (= déjà existant dans
CLLocationManager
) de mettre en œuvre un tel délai? - Sur quel thread le
CLLocationManager
appelle-t-il les méthodes de son délégué? - Si ce n'est pas le thread principal, je pourrais potentiellement avoir un problème où les commentaires le mettent en évidence. Comment puis-je contourner cela?
En fait, l'appel de délégué est fait sur le thread principal. Merci pour votre contribution précieuse. – aspyct