小编Rob*_*hai的帖子

CMPedometer(CoreMotion)实时更新

我发现有关此主题(CMPedometer)的资源非常有限。我想知道这里是否有人设法使它正常工作。我的代码非常简单,并且具有比我想做的更多的功能。基本上,步数计数器不会使用户执行的每一步都递增。

它实际上是在跟踪用户执行的每个步骤,但更新速度如此之慢,我不知道为什么。我什至尝试使用NSTimer发出每半秒更新标签的请求。我想尝试让步数计数器在用户迈出一步时进行更新。这是我的代码...

#import "ViewController.h"
#import <CoreMotion/CoreMotion.h>

@interface ViewController ()

@property (nonatomic, strong) CMPedometer    *pedometer;
@property (nonatomic, weak) IBOutlet UILabel *startDateLabel;
@property (nonatomic, weak) IBOutlet UILabel *endDateLabel;
@property (nonatomic, weak) IBOutlet UILabel *stepsLabel;
@property (nonatomic, weak) IBOutlet UILabel *distanceLabel;
@property (nonatomic, weak) IBOutlet UILabel *ascendedLabel;
@property (nonatomic, weak) IBOutlet UILabel *descendedLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    if ([CMPedometer isStepCountingAvailable]) {
        self.pedometer = [[CMPedometer alloc] init];
        [NSTimer scheduledTimerWithTimeInterval:0.5f
                                         target:self
                                       selector:@selector(recursiveQuery)
                                       userInfo:nil
                                        repeats:YES];
    } else {
        NSLog(@"Nothing available");
        self.startDateLabel.text = …
Run Code Online (Sandbox Code Playgroud)

objective-c ios core-motion

5
推荐指数
1
解决办法
1924
查看次数

标签 统计

core-motion ×1

ios ×1

objective-c ×1