2017-03-02 58 views
0

我需要跟踪用户何时旅行。为此,我设置CLLocationManager这样的:iOS:跟踪用户移动24/7

self.locationManager.requestAlwaysAuthorization() 
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters 
self.locationManager.distanceFilter = 200      
self.locationManager.pausesLocationUpdatesAutomatically = false      
self.locationManager.allowsBackgroundLocationUpdates = true 
self.locationManager.activityType = .other 

所以我的应用程序变得更加如果它没有运行的位置,保存在数据库中的位置,并再次得到背景。稍后,当用户启动应用程序时,旅行将从db中的新位置提取。

这或多或少的工作能耗约为15%。该位置是通过手机信号塔而不是gps来确定的。

我意识到在某些日子里,某些地区(火车轨道)的跟踪功能不起作用。你知道为什么会发生这种情况吗? (仅限iOS10设备)。

您是否看到改进以实现我的目标?还有什么可以用来确定旅行吗? (如果您的通勤时速超过15公里/小时且超过15分钟,则为旅行)。

感谢

回答

1

可以有多个活动类型,它可以帮助你找到曲目,船等以下是对活动类型的苹果文档:

public enum CLActivityType : Int { 


    case other 

    case automotiveNavigation // for automotive navigation 

    case fitness // includes any pedestrian activities 

    case otherNavigation // for other navigation cases (excluding pedestrian navigation), e.g. navigation for boats, trains, or planes 
} 

您可以使用self.locationManager.activityType = .otherNavigation