Detecting if a user is moving in a car

前端 未结 4 959
一整个雨季
一整个雨季 2020-12-04 10:27

NOTICE: This question was originally posted before Apple introduced motion-detection hardware and associated APIs in the iOS SDK. Answers to

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 10:58

    Xcode 7.3, iOS 9.3

    Thanks to all the original contributors.

    I just spent a few hours trying to understand why this fairly straight forward class was not working for me. I used all the suggestion above and from other posts to see what activity iOS thought the user was performing using Core Motion framework and using the CMMotionActivityManager class.

    Turns out that for whatever reason I had my "Fitness Tracking" in "Settings"->"Privacy"->"Motion & Fitness" turned off. And for whatever reason after adding the framework and calling a CM class, the app. did not request to enable this. I must have turned this off manually.

    Eventually I stumbled onto this post...

    iOS - is Motion Activity Enabled in Settings > Privacy > Motion Activity

    Which lead me to check the setting and resolve the issue. After I flipped "Fitness Tracking" to on and ran the app. again, everything worked like a charm.

    Hopefully this saves someone some time! Cheers.

提交回复
热议问题