我正在研究为什么在设备锁定时使用“重大位置更改”时,locationManager:didUpdateLocations:
没有被触发。
到目前为止,locationManager:didUpdateLocations:
仅在通过按Home按钮唤醒设备后才会触发新位置的更新。
我正在使用iOS 8.1,但不知道这是否是正常行为。
以下是我的代码(AppDelegate.m):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]){
NSLog(@"LAUNCHED BY LOCATION UPDATE");
}
[self startLocationTrack];
}
-(void)startLocationTrack
{
if (_locationManager == nil) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.pausesLocationUpdatesAutomatically = NO;
_locationManager.activityType = CLActivityTypeAutomotiveNavigation;
_locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
if ([_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[_locationManager requestAlwaysAuthorization];
}
[_locationManager startMonitoringSignificantLocationChanges];
}else{
[_locationManager startMonitoringSignificantLocationChanges];
}
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)location
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:5]];
notification.timeZone = [NSTimeZone defaultTimeZone];
[notification setSoundName:UILocalNotificationDefaultSoundName];
notification.alertBody = @"YOU HAVE MOVE A SIGNIFICANT DISTANCE!!";
notification.alertAction = NSLocalizedString(@"Read Msg", @"Read Msg");
notification.applicationIconBadgeNumber=0;
notification.repeatInterval=0;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}