2014-11-25 57 views
0

我明显缺少一些基本的东西。我忙于监视重要位置更改的应用程序。我运行该应用程序。然后完全关闭它,必要时会触发我委托中的更新位置,但我的位置为零。iOS重要位置更改和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

在iOS系统,你想吗? – 2014-11-25 07:50:51

+0

最新版本8.1.1 – Ims 2014-11-25 07:58:50

回答

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]; 
     } 
+0

您好,我在切换到iOS 8时已经这样做了。 – Ims 2014-11-25 08:04:02

+0

它在iOS 6/7上工作吗? – 2014-11-25 08:07:05

+0

我没有真正检查,因为我不支持iOS 6,但我会尝试iOS 7,看看是否可行 – Ims 2014-11-25 08:08:43

0

在iOS系统9这就是我所做的,在plist中我说:

<key>NSLocationAlwaysUsageDescription</key> 
<string>Location is required to find out where you are</string> 

在课堂上你使用Core Locati关于经理

- (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]; 
} 
相关问题