2016-04-24 46 views
1

我正在開發一個應用程序,該應用程序在用戶駕駛車輛時彈出消息。我已經實現了SOMotionDetector庫。這個庫的效果很好,但我不想跟蹤用戶的位置,我絕對不想顯示一條消息詢問他們的位置的權限。有另外一種選擇嗎?iOS:沒有GPS,是否有可能檢測到用戶是否在駕駛車輛?

這裏是我已經添加的編碼,不知道它是否會有所幫助。

[SOLocationManager sharedInstance].allowsBackgroundLocationUpdates = NO; 

[[SOMotionDetector sharedInstance] startDetection]; 

[SOMotionDetector sharedInstance].useM7IfAvailable = YES; //Use M7 chip if available, otherwise 

[SOMotionDetector sharedInstance].motionTypeChangedBlock = ^(SOMotionType motionType) { 
    switch (motionType) { 
     case MotionTypeNotMoving: 
      break; 
     case MotionTypeWalking: 
      break; 
     case MotionTypeRunning: 
      break; 
     case MotionTypeAutomotive:[self alertMessage]; 
      break; 
    } 
}; 
+0

我相信'automotive'運動型GPS時,爲了賴以確定高速移動,但您不需要請求位置權限,因爲您沒有訪問用戶的位置;這是如果您直接在CoreMotion框架中使用。我不知道什麼'SOMotionDetector'。但是,CoreMotion沒有後臺通知,因此如果您希望應用在後臺接收動態更新,則需要利用其中一種支持的後臺模式,其中位置更新爲一個 – Paulw11

+0

Hello @ Weakman10122,我也在搜索用於檢測用戶是否在駕駛車輛。你能分享一下你是如何實現這個的。感謝您期待您的回覆。 – ChanWarde

+0

@ChanWarde使用此庫https://github.com/SocialObjects-Software/SOMotionDetector。它上次運行良好,我使用它。 – Weakman10122

回答

3

是的,這是可能的。

  1. 您可以在設備上使用Core Motion來獲取用戶是否可能駕駛的 。 CoreMotion API會爲您提供iOS最佳 關於用戶活動的猜測,但不能保證其準確性爲100% 。 (例如,我不確定是否乘坐火車的次數可能會計爲 作爲汽車。另請注意,不同的活動類型不是 互斥)。您的應用程序最好檢查您感興趣的 活動類型比試圖排除你不想要的 。
  2. 用以下方法檢查用戶的當前速度。如果用戶 行駛超過20上下的MPH快,那麼我可以假設 用戶是在汽車:

    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { 
        CLLocation *recentLocation = [locations lastObject]; 
        recentLocation.speed; //If speed is over 20 MPH, assume the user is not on their feet. 
        } 
    
+0

鏈接到Apple網站上的相關Core Motion API:[CMMotionActivity類參考](https://developer.apple.com/library/ios/documentation/CoreMotion/Reference/CMMotionActivity_class/index.html#//apple_ref/c/ tdef/CMMotionActivityConfidence) –

+0

是否可以在後臺獲取或者如果我的應用程序被殺害? – netshark1000

相關問題