iOS - is Motion Activity Enabled in Settings Privacy Motion Activity
New in iOS 11, CMSSensorRecorder has a static method called authorizationStatus to retrieve it.
+ (CMAuthorizationStatus)authorizationStatus;
iPhone - requesting Motion activity
Essentially, use can first be sure that the alert view will not block your App, when the first view has appeared, ie. in onViewDidAppear.
For example do:
-(void) viewDidAppear:(BOOL)animated {
if ([MyActivityManager checkAvailability]) { // motion and activity availability checks
[myDataManager checkAuthorization:^(BOOL authorized) { // is authorized
dispatch_async(dispatch_get_main_queue(), ^{
if (authorized) {
// do your UI update etc...
}
else {
// maybe tell the user that this App requires motion and tell him about activating it in settings...
}
});
}];
}
}
This is what I do myself. I based my App on the Apple example code as well and noticed, that the example also has the problem you are describing.
CMMotionActivityManager callback when user not allow the permisson
you just can ... picking the error:
[stepCounter queryStepCountStartingFrom:[NSDate date]
to:[NSDate date]
toQueue:[NSOperationQueue mainQueue]
withHandler:^(NSInteger numberOfSteps, NSError *error) {
if (error != nil && error.code == CMErrorMotionActivityNotAuthorized) {
// The app isn't authorized to use motion activity support.
}
from here: iOS - is Motion Activity Enabled in Settings > Privacy > Motion Activity
CMMotionactivitymanager authorizationstatus
CMMotionActivityManager does not currently offer a way to check authorisation status directly like other frameworks.
iOS - is Motion Activity Enabled in Settings > Privacy > Motion Activity
However, as the comments in the above question mention, if you attempt a query using
queryActivityStartingFromDate:toDate:toQueue:withHandler
and the user has not authorised your application, the handler (CMMotionActivityQueryHandler) will return this error.
CMErrorMotionActivityNotAuthorized
CoreMotion - way to determine if motion is disabled in iOS Settings?
You are confusing two separate things called "motion". CMMotionManager is used to access the sensors, such as the gyroscope and accelerometer, that report how a user physically moves a device. It has nothing to do with the motion effects, like UIMotionEffect objects, that are used in animating views.
The deviceMotionActive method merely indicates whether your app is currently registered for receiving motion updates from CoreMotion. This will only be true if your app has called one of the CMMotionManager startXXXUpdate methods. Again, it has nothing to do with user settings or UIMotionEffect objects.
UPDATE: As John mentions in the comments, there appears to be an API for this in iOS 8: See stackoverflow.com/a/25453082/2904769 .
Related Topics
Why Is Allocating or Initializing Nsdateformatter Considered "Expensive"
Region Monitoring Glitch on iOS 7 - Multiple Notifications at the Same Time
Objective-C Wrapper for Cfunctionpointer to a Swift Closure
Nsurlsessiondatatask Datataskwithurl Completion Handler Not Getting Called
How to Change the Color of Uipickerview Selector
Uicolor Colorwithred:Green:Blue:Alpha: Always Returns White Unless One Argument Is 0
How to Load Icarousel View from Storyboard or Xib
Intercept Objective-C Delegate Messages Within a Subclass
Invalid Image Path - No Image Found at the Path. Cfbundleicons Xcode 5
Is It Ok to Place Most Logic and Models in the Appdelegate
How to Detect iOS 6 and All Minor Versions by User Agent
Is This Code Drawing at the Point or Pixel Level? How to Draw Retina Pixels
Urlresponse Is Not Retrieved After Storing in Cache Using Storecachedresponse