【问题标题】:iOS GPS Battery drain, how to make it less drain?iOS GPS 电池耗电,如何减少耗电?
【发布时间】:2012-03-23 17:31:26
【问题描述】:

我的服务需要 GPS。我实际上实现了一项服务,它打开 gps,检查位置是否有效,然后进入休眠状态一段时间。 (从 5 秒开始,如果没有检测到移动,它最多可以休眠一分钟) 之后,我再次启动 gps,并获得一个新位置。

但是电池消耗仍然很高!我使用了 locMgr.distanceFilter = 10.0f 和 desiredAccurady = NearestTenMeters。

如何最大限度地减少电池消耗?

【问题讨论】:

    标签: ios


    【解决方案1】:

    这就是我的处理方式。获取位置后,我将其存储在 NSDictionary 中。然后,如果我需要再次定位,我会返回 NSDictionary 而不是重新打开 GPS。 2 分钟后,我重置了 NSDictionary(您可以将时间调整为最适合您应用的套件)。然后在 NSDictionary 重置后下次我需要该位置时,我会从 GPS 中获取一个新位置。

    - (NSDictionary *) getCurrentLocation {
    
    if (self.currentLocationDict == nil) {
        self.currentLocationDict = [[NSMutableDictionary alloc] init];
    
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
        locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
        locationManager.distanceFilter = kCLDistanceFilterNone;
        [locationManager startUpdatingLocation];
    
        CLLocation *myLocation = [locationManager location];
    
        [self.currentLocationDict setObject:[NSString stringWithFormat:@"%f", myLocation.coordinate.latitude] forKey:@"lat"];
        [self.currentLocationDict setObject:[NSString stringWithFormat:@"%f", myLocation.coordinate.longitude] forKey:@"lng"];
        [locationManager stopUpdatingLocation];
        [locationManager release];
    
        //Below timer is to help save battery by only getting new location only after 2 min has passed from the last time a new position was taken.  Last location is saved in currentLocationDict
        [NSTimer scheduledTimerWithTimeInterval:120 target:self selector:@selector(resetCurrentLocation) userInfo:nil repeats:NO];
    }
    
    return self.currentLocationDict;
    }
    
    - (void) resetCurrentLocation {
    NSLog(@"reset");
    [currentLocationDict release];
    self.currentLocationDict = nil;
    }
    

    【讨论】:

    • 这不是我想要的。需要更多关于电池消耗的信息。
    猜你喜欢
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多