Я пытаюсь написать метод для возврата текущего местоположения.Пока я жду 30 секунд, 1 минуту или 2 минуты (задано в настройках), я отображаю предупреждение.Я разрешаю пользователю обойти ожидание таймера с помощью кнопки alertView, принимающей текущую точность, которую я буду отображать и обновлять в виде предупреждения.В моем коде есть пара дыр, с которыми мне нужна помощь.По сути, нужно знать, как заставить метод getCurrentLocation ожидать таймер.Я не могу просто использовать задержку, потому что я планирую заставить истечь таймер, если пользователь нажимает кнопку или если точность местоположения соблюдается (это проверяется таймером).Вот код:
- (void)timerFireMethod {
static int elapsedTime = 0;
elapsedTime++;
if (elapsedTime >= gpsTimeout) {
[locationManager stopUpdatingLocation];
elapsedTime = 0; // reset static variable
// !!! How do I do the following !!!
// do something to allow getCurrentLocation to return
}
if ((currentLocation.horizontalAccuracy <= gpsDesiredAccuracy) & (currentLocation.verticalAccuracy <= 2*gpsDesiredAccuracy)) {
[locationManager stopUpdatingLocation];
elapsedTime = 0; // reset static variable
// do something to allow getCurrentLocation to return
}
}
- (CLLocation *)getCurrentLocation {
// check if current accuracy is good enough and return if true
if ((currentLocation.horizontalAccuracy <= gpsDesiredAccuracy) & (currentLocation.verticalAccuracy <= 2*gpsDesiredAccuracy)) {
[locationManager stopUpdatingLocation];
return currentLocation;
} else {
// show alert with count down timer
UIAlertView *gpsAlertView = [[UIAlertView alloc] initWithTitle:nil message:@"tbd put in timer and list location accuracy updates" delegate:self cancelButtonTitle:@"Continue With Current Accuracy" otherButtonTitles:nil];
[gpsAlertView show];
// start timer
NSTimer *gpsTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(timerFireMethod:)
userInfo:nil repeats:YES];
// !!! How do I do the following !!!
// wait for when timer expires,
// the user to press "Continue With Current Accuracy" button (can force timer to expire?)
return currentLocation;
}
}