【发布时间】:2015-01-07 02:55:21
【问题描述】:
我以多种方式使用 M7/M8 芯片的 MotionActivity,包括计步。对于计步,我会查询当天的步数,并在实时发生时不断请求步数。
目前在执行此操作之前,我会先检查 [CMStepCounter isStepCountingAvailable] 以及本地覆盖标志,然后再继续执行此代码。我假设 isStepCountingAvailable 如果未授予 motionActivity 授权,将返回 FALSE。情况似乎并非如此,它似乎更像是一种硬件检测。我似乎找不到其他方法来检测是否为此授予了授权。
这意味着 startStepCountingUpdatesToQueue 和 queryStepCountStartingFrom 都运行并返回块,但总是返回错误代码。特别是 CMErrorDomain 代码 105。
我有没有更好的方法来确定motionActivity 是否未经授权?我有一些备用代码,但我更喜欢事先进行布尔检查,而不是返回块中的错误代码。
if (self.useM7IfAvailable && [CMStepCounter isStepCountingAvailable]){
self.cmStepCounter = [[CMStepCounter alloc] init];
[self.cmStepCounter startStepCountingUpdatesToQueue:self.operationQueue updateOn:1.0 withHandler:^(NSInteger numberOfSteps, NSDate *timestamp, NSError *error){
if(!error){
// do something with numberOfSteps
} else {
// not authorized: CMErrorDomain code 105
}
}];
}
[self.cmStepCounter queryStepCountStartingFrom:dayStart to:dayEnd toQueue:_operationQueue withHandler:^(NSInteger numberOfSteps, NSError *error) {
if(!error){
// do something with numberOfSteps
} else {
// not authorized: CMErrorDomain code 105
}
}];
【问题讨论】:
标签: ios authorization apple-m7