我从核心运动中得不到任何步骤 我需要距离该步数数英里的距离
let convertedDistance = self.distance / 1609.344
let roundedDistanceinMiles = String(format: "%.2f", convertedDistance)
答案 0 :(得分:2)
**在iOS8中使用计步器查找步数**
#import <CoreMotion/CoreMotion.h>
@interface HomeView : UIViewController
{
}
@property(strong,nonatomic) CMPedometer *pedometer;
in .m File
@interface HomeView ()
{
}
@end
@implementation HomeView
@synthesize pedometer;
- (void)viewDidLoad
{
pedometer=[[CMPedometer alloc]init];
[pedometer queryPedometerDataFromDate:midnightLastNight toDate:now1 withHandler:^(CMPedometerData *pedometerData, NSError *error)
{
if (pedometerData!=nil)
{
NSString *numberofsteps=[NSString stringWithFormat:@"%@",pedometerData.numberOfSteps];
totalsteps=[numberofsteps intValue];
}
}];
}
答案 1 :(得分:1)
您可以使用CMPedometerData
中的distance
属性,该属性以米为单位提供您不需要转换步骤的距离。
答案 2 :(得分:-1)
else
{
float mileDistance =roundf([distance floatValue] * 0.621371);
if (mileDistance==0)
{
mileDistance=0.04;
return [NSString stringWithFormat:@"%d mi",(int)mileDistance];
}
else
{
return [NSString stringWithFormat:@"%d mi", (int)mileDistance];
}
}