2

I am using the following code from the Privacy Prompts project to get the Motion Permission.

- (void)requestMotionAccessData {
    self.cmManager = [[CMMotionActivityManager alloc] init];
    self.motionActivityQueue = [[NSOperationQueue alloc] init];
    [self.cmManager startActivityUpdatesToQueue:self.motionActivityQueue withHandler:^(CMMotionActivity *activity) {
        /* 
         * Do something with the activity reported
         */

        NSLog(@"requestMotionAccessData");
        [self alertViewWithDataClass:Motion status:NSLocalizedString(@"ALLOWED", @"")];
        [self.cmManager stopActivityUpdates];
    }];
}

What if user not allow the motion permission. Do i get some callback? If not is there an alternative way to get the this. I want the callback when user selects Allow or Don't Allow

4

1 回答 1

2

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

于 2014-06-19T09:32:01.987 回答