2016-04-24 40 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

相关问题