繁体   English   中英

手动要求用户访问照片或相机

[英]Manually ask user to access photos or camera

我想知道如何在按下按钮时在屏幕上显示“此应用程序想访问您的照片/相机:不允许,允许”。 我有代码来检查是否启用了照片或照相机,但是没有代码来启用或禁用该操作。 如何为每个人(照片和相机)执行此操作?

在Obj C

-(void)showImagePicker
{
    if ([AVCaptureDevice respondsToSelector:@selector(requestAccessForMediaType: completionHandler:)]) {
            [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    if (granted) {
    // Here you can implement your functions.
                    } else {
    // This condition executes when the user taps Don't Allow option on the alertVeiw. This alert is an one time alert. so you may need to reset the privacy and location settings in your device settings.
                        [self cancel];
                    }
                });
            }];
        } else {
            [self cancel];
        }
}

轻触提到的按钮时,请执行以下操作:

OBJ-C:

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus authorizationStatus) {
    if (authorizationStatus == PHAuthorizationStatusAuthorized) {
        // Add your custom logic here
    }
}];

迅速:

PHPhotoLibrary.requestAuthorization { (authorizationStatus) -> Void in
    if authorizationStatus == .Authorized {
        // Add your custom logic here
    }
}

如果需要,将弹出允许访问照片库的系统弹出窗口。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM