iPhone使用Objective-C关闭GPS

Jam*_*sta 4 iphone gps

有谁知道如何以编程方式关闭iPhone的GPS?一旦我使用CLLocationManager获取我的位置的三次读取,我将停止更新位置,如下面的代码所示:

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation {

if((newLocation.horizontalAccuracy >  0.0f) &&
   (newLocation.horizontalAccuracy < 7000.0f) ){

    if(self.locations.count > 3){
        [self.locationManager stopUpdatingLocation];
    }
    [self.locations addObject:newLocation];
}
Run Code Online (Sandbox Code Playgroud)

但是,当用户使用我的应用程序并耗尽电池时,这似乎仍然会启用GPS.我需要做的就是读取位置三次,以便我可以获得准确的读数,然后关闭GPS.有人知道如何用Objective-C关闭GPS吗?

mik*_*tew 5

stopUpdatingLocation为位置管理器提供关闭硬件的选项,但不保证.当没有其他人需要它时,它应该关闭硬件.在实践中,它似乎按照人们的预期工作.

是否有可能永远不会调用stopUpdatingLocation?在上面的代码段中,您的代码永远不会进入该调用,这看起来并不合理.