[英]iOS Significant Location Change and didUpdateLocations
I'm obviously missing something basic here. 我显然在这里缺少基本的东西。 I am busy with an app that monitors significant location changes. 我正忙于监视重大位置变化的应用程序。 I run the app. 我运行该应用程序。 and then close it completely, didUpdateLocations in my delegate is fired when it's necessary, but my location is nil. 然后将其完全关闭,必要时会触发我的委托中的didUpdateLocations,但我的位置为nil。
- (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);
}
any thoughts/help? 有什么想法/帮助吗?
Thanks 谢谢
Add this to your plist 将此添加到您的列表
<key>NSLocationAlwaysUsageDescription</key>
<string></string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
And this code 而这段代码
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
if(IS_OS_8_OR_LATER) {
[locationManager requestAlwaysAuthorization];
}
In iOS 9 this what I did, in plist I added: 在iOS 9中,我所做的就是在plist中添加的内容:
<key>NSLocationAlwaysUsageDescription</key>
<string>Location is required to find out where you are</string>
In class you use Core Location Manager 在课堂上,您使用Core Location Manager
- (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
}
}
And in the delegate I start monitoring significant location services 在代表中,我开始监视重要的位置服务
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"App going to the background");
[_locationManager startMonitoringSignificantLocationChanges];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.