Использование iOS 8 и наличие NSLocationAlwaysUsageDescription.iOS Geolocation Не обновляется
Вот мой код:
#import "GeoLocation.h"
#import "AppDelegate.h"
@implementation GeoLocation
- (id)init
{
self = [super init];
if (self)
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = 5; //in meters
// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization];
}
self.numberOfUpdates = 0;
[self.locationManager startUpdatingLocation];
}
return self;
}
// Wait for location callbacks
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"Location Updated: %@", [locations lastObject]);
}
- (float) getLatitude
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSLog(@"getLatitude: %f", self.locationManager.location.coordinate.latitude);
appDelegate.gMyProfile.latitude = self.locationManager.location.coordinate.latitude;
return self.locationManager.location.coordinate.latitude;
}
- (float) getLongitude
{
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSLog(@"getLongitude: %f", self.locationManager.location.coordinate.longitude);
appDelegate.gMyProfile.longitude = self.locationManager.location.coordinate.longitude;
return self.locationManager.location.coordinate.longitude;
}
- (float) getAltitude
{
return self.locationManager.location.altitude;
}
Когда пользователь входит в систему, я создаю экземпляр геолокации объекта, который начинается включить обновления местоположения.
Если я использую self.locationManager.distanceFilter = 5; и прогуляться по моему дому, didUpdateLocations не будет срабатывать.
Однако, если я избавлюсь от self.locationManager.distanceFilter = 5; сделалUpdateLocations будет срабатывать каждую секунду.
Все, что вы, ребята, видите, что я нет. Я хотел бы, чтобы это обновлялось, когда пользователь перемещается на 5 метров.
У вас есть Wi-Fi включен? Попробуйте отключить его. –