startMonitoringSignificantLocationChanges在后台应用程序时每47秒调用一次

时间:2015-06-02 07:29:08

标签: ios objective-c cllocationmanager

为后台添加了

startMonitoringSignificantLocationChanges,并且在后台应用程序中每个- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations调用了委托“47 sec”。 如果应用程序在同一个地方,我不想点击服务器api提交位置,如果位置已经改变,那么我想提交lat&很长的服务器。

它耗尽了iphone电池。我想节省我们应用程序发生的电池消耗。

请建议。

1 个答案:

答案 0 :(得分:1)

您需要在初始化位置管理器的位置正确设置desiredAccuracy,distanceFilter,headingFilter(如果需要)。

/* Pinpoint our location with the following accuracy:
 *
 *     kCLLocationAccuracyBestForNavigation  highest + sensor data
 *     kCLLocationAccuracyBest               highest     
 *     kCLLocationAccuracyNearestTenMeters   10 meters   
 *     kCLLocationAccuracyHundredMeters      100 meters
 *     kCLLocationAccuracyKilometer          1000 meters 
 *     kCLLocationAccuracyThreeKilometers    3000 meters
 */
self.your_locationManager_object.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;

/* Notify changes when device has moved x meters.
 * Default value is kCLDistanceFilterNone: all movements are reported.
 */
self.locationManager.distanceFilter = 10.0f;

/* Notify heading changes when heading is > 5.
 * Default value is kCLHeadingFilterNone: all movements are reported.
 */
self.locationManager.headingFilter = 5;

// update location
if ([CLLocationManager locationServicesEnabled]){
    [self.locationManager startUpdatingLocation];
}