Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if user gave access to the "Motion and Fitness" permission within my iOS app

I'm building an iPhone app (9.0.2) on XCode 7.0. Was wondering what the best way is to determine if a user gave access to the Motion and Fitness permission from within my app.

I'm mainly working with the CMMotionActivityManager class. There is a property called + isActivityAvailable but that returns true even when the Motion and Fitness permission is set to false.

Thanks!

like image 235
Eugene Avatar asked Jan 23 '26 12:01

Eugene


1 Answers

According to Apple's documentation, [CMMotionActivityManager isActivityAvailable] returns a boolean of whether the current device supports motion data, not if the user has given the app permission to use it.

For permissions, the only way to check whether the user has given permission is through error handling. When the method you are invoking requires permissions, but the app is not authorized by the user, an CMErrorMotionActivityNotAuthorized error code will be thrown.

From there, you can capture this error and prompt the user to give this app permissions. That's how Apple's sample project (Swift) does it.

like image 179
dennykim Avatar answered Jan 25 '26 11:01

dennykim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!