什么是最好的iOS GPS(CLLocationManager)电池节电技术

时间:2017-09-04 20:40:05

标签: ios gps cllocationmanager cllocation unnotificationtrigger

我一直在为iOS 10编写GPS应用程序。我已经达到了稳定和按预期工作的程度,现在我想继续 节电技术。该应用程序现在每5分钟发送一次GPS位置,但我可以灵活地发送GPS位置的频率 因为他们不经常发送。我的应用需要“最好的”#39;或者' 10m'我所知道的GPS位置设置使用了很多功率,但我不能按照我的要求使用3km设置(我知道可以节省更多功率)。

从我收集和阅读文档以及使用代码来使其工作,似乎有两种技术:

  1. 与UNLocationNotificationTrigger一起设置pausesLocationUpdatesAutomatically = YES
  2. allowDeferredLocationUpdatesUntilTraveled:超时:
  3. 根据iOS 10和11中的this article,数字2显然根本不起作用。

    当我将其记录到我的服务器时,数字1给出了零星的结果。有时它可以工作,有时我会在不知道的地方获得一个GPS点(没有看到暂停或恢复日志消息)然后它开始工作,有时它似乎根本不起作用。

    有时候,我会在同一秒内看到2次暂停。

    其他时候我看到它在没有看到暂停日志消息的情况下背靠背(分开几分钟)恢复位置。有时我会看到暂停日志消息,几分钟后(或稍后一段时间)恢复GPS发送,而不会看到'恢复'记录消息。

    - (void) setGPSBatterySavingTrigger
    {
        if (IS_IOS_10_OR_LATER && ([g_prefs getGPSAuthStatus] == kCLAuthorizationStatusAuthorizedAlways))
        {
            CLLocationCoordinate2D center = CLLocationCoordinate2DMake(g_locMgr.getLastLocation.latitude, g_locMgr.getLastLocation.longitude);
            CLRegion *region = nil;
            float radius_m = 150.0;
            region = [[CLCircularRegion alloc] initWithCenter:center radius:radius_m identifier:@"pauseLocationsCenter"];
    
            if (!region) {
                [logger log:TSERVLOG :@"pause radius failed at radius <%f>", radius_m];
                return;
            }
            region.notifyOnEntry = NO;
            region.notifyOnExit = YES;
    
            UNLocationNotificationTrigger *trigger = [UNLocationNotificationTrigger
                                                      triggerWithRegion:region repeats:NO];
    
            UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
            content.title = PROG_NAME;
            content.body = @"GPS Restarted";
            //content.sound = [UNNotificationSound soundNamed:nil];
    
            UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"GPSTextNotify" content:content trigger:trigger];
    
            [[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests];
            [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError *error)
             {
                 if (error.code)
                 {
                     [logger log:TSERVLOG :@"UNUserNotificationCenter addRequest FAILED <%@>", error.localizedDescription];
                 }
             }];
        }
    }
    
    - (void) locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager
    {
        [logger log:TSERVLOG :@"===== JME GPS PauseLocationUpdates at <%@> <%f, %f>",
                [mydate getCurrentDateTimeStr], self.getLastLocation.latitude, self.getLastLocation.longitude];
    
        [self setGPSBatterySavingTrigger];
    }
    
    - (void) locationManagerDidResumeLocationUpdates:(CLLocationManager *)manager
    {
        [logger log:TSERVLOG :@"===== GPS ResumeLocationUpdates at <%@> <%f, %f>",
                [mydate getCurrentDateTimeStr], self.getLastLocation.latitude, self.getLastLocation.longitude];
    }
    

    底线问题:

    1. 有没有人能够使用其中任何一种来节省电池+ GPS在iOS 10 +中可靠运行?
    2. 如果没有,为了节省电池寿命,你有什么组合可以让它在100%的时间内正常工作?
    3. 我错过了另一种有效的技术吗? (注意我的要求不能使用3km设置)
    4. 感谢您的投入!

0 个答案:

没有答案
相关问题