SOMotionDetector 1.0.2

SOMotionDetector 1.0.2

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2016年3月

由 [arturdev] 保持。



  • Artur Mkrtchyan

这是一个简单的库,用于检测 iOS 上的运动,由 arturdev 提供。

基于位置更新和加速度。

要求

iOS > 6.0

兼容 iOS 7

所有 iOS 设备都适用(即不需要 M7 芯片)

此示例项目还展示了如何使用此库重新启动处于已杀状态的应用。

使用方法

SOMotionDetector 文件夹复制到您的项目中。

连接到 CoreMotion.frameworkCoreLocation.framework

导入 "SOMotionDetector.h" 文件并设置 SOMotionDetector 的回调函数

#import "SOMotionDetector.h

//...

[SOMotionDetector sharedInstance].motionTypeChangedBlock = ^(SOMotionType motionType) {
    //...
};

[SOMotionDetector sharedInstance].locationChangedBlock = ^(CLLocation *location) {
    //...
};

[SOMotionDetector sharedInstance].accelerationChangedBlock = ^(CMAcceleration acceleration) {
    //...    
};

注意!

为了支持 iOS > 8.0,您必须在您的 info.plist 文件中添加以下键之一
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription

为了在 iOS > 9.0 中启用后台位置更新,您必须将 allowsBackgroundLocationUpdates 设置为 YES

    [SOLocationManager sharedInstance].allowsBackgroundLocationUpdates = YES;

完成!

现在,要开始检测运动,只需调用

[[SOMotionDetector sharedInstance] startDetection];

要停止检测,请调用

[[SOMotionDetector sharedInstance] stopDetection];

要开始计步,请调用

    [[SOStepDetector sharedInstance] startDetectionWithUpdateBlock:^(NSError *error) {
        //...
    }];

检测运动类型

typedef enum
{
  MotionTypeNotMoving = 1,
  MotionTypeWalking,
  MotionTypeRunning,
  MotionTypeAutomotive
} SOMotionType;

自定义

/**
 * Set this parameter to YES if you want to use M7 chip to detect more exact motion type. By default is No.
 * Set this parameter before calling startDetection method.
 * Available only on devices that have M7 chip. At this time only the iPhone 5S, the iPad Air and iPad mini with retina display have the M7 coprocessor.
 */
@property (nonatomic) BOOL useM7IfAvailable;

/**
 *@param speed  The minimum speed value less than which will be considered as not moving state
 */
- (void)setMinimumSpeed:(CGFloat)speed;

/**
 *@param speed  The maximum speed value more than which will be considered as running state
 */
- (void)setMaximumWalkingSpeed:(CGFloat)speed;

/**
 *@param speed  The maximum speed value more than which will be considered as automotive state
 */
- (void)setMaximumRunningSpeed:(CGFloat)speed;

/**
 *@param acceleration  The minimum acceleration value less than which will be considered as non shaking state
 */
- (void)setMinimumRunningAcceleration:(CGFloat)acceleration;

Podfile

pod "SOMotionDetector"

许可证

SOMotionDetector 使用 MIT 许可证(见 LICENSE 文件)