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

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



Leave a reply



Submit