我显然在这里缺少一些基本的东西。我正忙着一个监控重要位置变化的应用程序。我运行应用程序。然后完全关闭它,我的委托中的didUpdateLocations在必要时被触发,但我的位置是零。
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
NSLog(@"didUpdateLocations: %@", [locations lastObject]);
CLLocation* location = [locations lastObject];
NSLog(@"latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
}
任何想法/帮助?
由于
答案 0 :(得分:0)
将此添加到您的plist
<key>NSLocationAlwaysUsageDescription</key>
<string></string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
这段代码
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
if(IS_OS_8_OR_LATER) {
[locationManager requestAlwaysAuthorization];
}
答案 1 :(得分:0)
在iOS 9中,这就是我所做的,我在plist中添加了:
<key>NSLocationAlwaysUsageDescription</key>
<string>Location is required to find out where you are</string>
在课堂上使用核心位置管理器
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
BOOL isInBackground = NO;
if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground)
{
isInBackground = YES;
}
if (isInBackground) {
// Do something while in the background
} else {
// while in use
}
}
在代表中,我开始监控重要的位置服务
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"App going to the background");
[_locationManager startMonitoringSignificantLocationChanges];
}