获取相机权限最多需要10秒钟

时间:2014-10-31 16:27:46

标签: ios xcode swift avfoundation uialertview

我需要检查相机权限。

如果权限失败,我会显示提醒。然而这需要10秒才能显示出来(不太好!)。

你能想到为什么花了这么长时间来获得权限吗?我甚至尝试在主线程上强制调用。

override func viewDidAppear(animated: Bool)
    {
        checkCameraPermissions()
        if(_viewInitialized == false)
        {
            //_view.initView()
            _viewInitialized = true
            _distanceBetweenTopAndMiddleBar = Int(_middleBar.frame.origin.y) - Int(_topBar.frame.origin.y) - Int(_topBar.frame.height)
        }
    }

    func checkCameraPermissions()
    {
        var status:AVAuthorizationStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
        if(status == AVAuthorizationStatus.Authorized)
        {
            return
        }else
        {
            dispatch_async(dispatch_get_main_queue())
            {
                AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo)
                {
                    allowed in
                    if(allowed == true)
                    {
                        return
                    }else
                    {
                        var alert:UIAlertView = UIAlertView(title: "Permission", message: "Ok", delegate: self, cancelButtonTitle: "OK")
                        alert.show()
                        alert.tag = 1
                    }
                }
            }
        }
    }

0 个答案:

没有答案