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


    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");
    }
  • 相关阅读:
    [php]php设计模式 Interpreter(解释器模式)
    [php]php设计模式 Decorator(装饰模式)
    [php]php设计模式 Adapter(适配器模式)
    [php]php设计模式 Delegation(委托模式)
    [php]php设计模式 Builder(建造者模式)
    [python]django学习笔记 二
    [ruby]ruby on rails学习笔记1
    [php]php设计模式 Factory(工厂模式)
    pku3461 Oulipo (KMP)
    pku 2406 && pku 1961 Period && hdu3746 Cyclic Nacklace
  • 原文地址:https://www.cnblogs.com/iOSJason/p/6726643.html
Copyright © 2020-2023  润新知