requestAccessForMediaType不需要许可 [英] requestAccessForMediaType doesn't ask for permission

查看:326
本文介绍了requestAccessForMediaType不需要许可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到我的应用程序未请求使用相机的权限.经过一些试验,我发现用于检查权限的那段代码需要很长时间才能完成.所以我想到了让我的viewdidload的那部分在串行队列(同步)上运行.在开始下一行之前,强制其余部分等待身份验证过程完成.但是,那实际上是行不通的.这些行按顺序开始,但仍然没有按顺序结束.

I noticed that my app doesn't request permission to use the camera. After some experimentation I figured out that the piece of code used to check permission takes a very long time to complete. So I thought of letting that part of my viewdidload run on a serial queue (sync). Forcing the rest to wait for the auth process to complete before starting the next line. But that doesn't really work. The lines start in order, but still don't finish in order.

奇怪的是,如果我只是请求权限而没有执行任何操作,没有完成处理程序(如下面的代码),那么他确实在第二次使用完善处理程序运行它时运行了,尽管它仍然没有显示给用户的警报.这可能是因为在欧洲不需要录制视频吗? avcapturedevice ref

The strange thing is if I just call for the permission and do nothing with it, no completionHandler (like the code below) then he does run the second time I run it with a completionHandler perfectly, although it still doesn't show an alert to the user. Can this be because recording video doesn't need permission in Europe? avcapturedevice ref

如果要逐行执行代码,是否需要使用屏障?或同步串行队列的或?

If I want to have code executed line by line, do I need to use barriers? or sync serial queue's or??

AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { nil }())


更新:


Update:

此方法应该很安全,但是事实并非如此.它返回true是理所当然的,但返回3的rawValue(被拒绝)

This method should be pretty fail safe, but it isn't. It returns true for granted, but 3 for the rawValue (denied)

func checkForAuthorizationStatus() {
        println("auth me")
        AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: {
            granted in
            if granted {
                println("granted: \(granted)")
                self.deviceAuthorized = true
                println("raw value: \(AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo).rawValue)")
            } else {
                self.deviceAuthorized = false
            }

        })
    }


更新2:在下面的评论中回答. -在设备上重置隐私设置以获取请求.


Update 2 : answer in comments below. - Reset privacy settings on device to get the request.

  • 授权的rawValue是3而不是4

推荐答案

如果要花很长时间才能显示出来,那么听起来好像您没有在主线程上运行它,应该这样做了.另外,如果以前已经提示过一次,则不会再次提示–用户必须进入设置"并启用摄像头访问权限.

If it's taking a long time to appear, then it sounds like you're not running this on the main thread, which you should be. Also, if it has prompted once before, it won't prompt again – the user has to go into Settings and enable camera access.

这篇关于requestAccessForMediaType不需要许可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆