2017-03-02 73 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