我正在开发一个应用程序,该应用程序在用户驾驶车辆时弹出消息。我已经实现了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;
}
};
我相信'automotive'运动型GPS时,为了赖以确定高速移动,但您不需要请求位置权限,因为您没有访问用户的位置;这是如果您直接在CoreMotion框架中使用。我不知道什么'SOMotionDetector'。但是,CoreMotion没有后台通知,因此如果您希望应用在后台接收动态更新,则需要利用其中一种支持的后台模式,其中位置更新为一个 – Paulw11
Hello @ Weakman10122,我也在搜索用于检测用户是否在驾驶车辆。你能分享一下你是如何实现这个的。感谢您期待您的回复。 – ChanWarde
@ChanWarde使用此库https://github.com/SocialObjects-Software/SOMotionDetector。它上次运行良好,我使用它。 – Weakman10122