3
我想知道爲什麼locationManager:didUpdateLocations:
在設備被鎖定時使用重要位置更改時未被觸發。當設備被鎖定時,重要的位置更改不能正確觸發
到目前爲止locationManager:didUpdateLocations:
被一個新位置觸發只有在按下主頁按鈕喚醒設備。
我使用的是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];
}