码迷,mamicode.com
首页 > 移动开发 > 详细

如何优雅地使用iOS系统相机

时间:2017-04-18 11:23:29      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:系统   dispatch   mission   cal   UI   eth   ios   class   normal   

NSString *mediaType = AVMediaTypeVideo; // Or AVMediaTypeAudio

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];

// This status is normally not visible—the AVCaptureDevice class methods for discovering devices do not return devices the user is restricted from accessing.
if(authStatus == AVAuthorizationStatusRestricted){
    NSLog(@"Restricted");
}

// The user has explicitly denied permission for media capture.
else if(authStatus == AVAuthorizationStatusDenied){
    NSLog(@"Denied");
}

// The user has explicitly granted permission for media capture, or explicit user permission is not necessary for the media type in question.
else if(authStatus == AVAuthorizationStatusAuthorized){
    NSLog(@"Authorized");
}

// Explicit user permission is required for media capture, but the user has not yet granted or denied such permission.
else if(authStatus == AVAuthorizationStatusNotDetermined){

    [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {

        // Make sure we execute our code on the main thread so we can update the UI immediately.
        //
        // See documentation for ABAddressBookRequestAccessWithCompletion where it says
        // "The completion handler is called on an arbitrary queue."
        //
        // Though there is no similar mention for requestAccessForMediaType, it appears it does
        // the same thing.
        //
        dispatch_async(dispatch_get_main_queue(), ^{

            if(granted){
                // UI updates as needed
                NSLog(@"Granted access to %@", mediaType);
            }
            else {
                // UI updates as needed
                NSLog(@"Not granted access to %@", mediaType);
            }
        });

    }];

}

else {
    NSLog(@"Unknown authorization status");
}

如何优雅地使用iOS系统相机

标签:系统   dispatch   mission   cal   UI   eth   ios   class   normal   

原文地址:http://www.cnblogs.com/iOSJason/p/6726643.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!