2014-06-18 44 views
2

我正在使用Privacy Prompts項目中的以下代碼來獲取運動權限。當用戶不允許使用CMMotionActivityManager回調

- (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]; 
    }]; 
} 

如果用戶不允許動作權限,該怎麼辦?我有一些回調嗎? 如果不是有其他方法來獲得這個。我想在回調時用戶選擇AllowDon't Allow

回答

2

你只可以...採摘錯誤:從這裏

[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. 
} 

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