iOS CMPedometer的使用

來源:互聯網
上載者:User

標籤:strong   star   calendar   day   注意   ntc   不用   公司   return   

一.介紹
CMPedometer是蘋果8.0推出的,之前的只能從物理引擎的架構去做,很是尷尬。而且不支援32位的系統,意味者iphone5和以後的型號都不支援這個。現在普遍好多了,現在的公司一般最低適配到8.0或者直接10.0系統,再也不用擔心這個問題了。
二.使用
先聲明一個屬性,不然他容易泄露,蘋果的好多架構都是這樣的,不能直接使用,得千萬注意
@property(nonatomic,strong)CMPedometer pedometer;

三.判斷許可權
pedometer =[[CMPedometer alloc] init];
pragma mark返回當天00:00

  • (NSDate )obtainTodayDate{
    return [NSDate date];
    }

pragma mark返回現在的時間

  • (NSDate )obtainNextTodayDate{

NSCalendar calendar = [NSCalendar currentCalendar];
NSDate now = [NSDate date];
NSDateComponents components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:now];
NSDate startDate = [calendar dateFromComponents:components];

return startDate;
}

[pedometer queryPedometerDataFromDate:nil toDate:nil withHandler:^(CMPedometerData Nullable pedometerData, NSError Nullable error) {

}]
四.注意
1.因為我擷取的是當天的時間,所以做法就很簡單了,擷取現在的時間,然後擷取第二天淩晨的時間,剛好就是一整天的時間
擷取步數,這個不能格式化成為本地時間,之前格式化過成為北京時間發現錯位8個小時.
2.蘋果的這個擷取步數,不能每秒即時擷取,容易錯誤,盡量1分鐘擷取一次好點,這樣能保證擷取成功
3.還有其他的方法,基本上很少用到,用到了直接看下注視就可以很清楚的看明白。

iOS CMPedometer的使用

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.