xcode - iOS10相机权限设置了之后用户点击不允许crash
PHPz
PHPz 2017-04-18 09:45:17
0
1
648

这两个Key设置好之后应该是相册和摄像头都可以调用的 但是现在的情况是相册的弹窗出来之后用户点击不允许就没事 访问相机用户点击不允许就会闪退……第二次进入APP就是正常提醒在隐私里开启授权了。
而且第一次出现弹出提示是否允许访问相机点击允许之后很长一段时间的黑屏甚至有的时候并不能打开相机 第二次有了授权之后这个黑屏就消失了
是我少了什么设置吗 相机这个不论点允许还是不允许都有问题

这两种情况遇到过吗?

PHPz
PHPz

学习是最好的投资!

reply all(1)
伊谢尔伦

Encountered the same problem.
When I reproduced it again, I set a global breakpoint when connecting to a real machine for debugging, and found that the crash occurred in the frame of setting a custom alertWindow.
I took a look and found that there is no null pointer in alertWindow.
Then the reason is obvious. A crash occurred when operating the UI. The reason was that the UI was not operated on the main thread.
Go back to the code and see the judgment of calling the camera status

let authStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
        switch authStatus {
        case .NotDetermined:
            AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { (granted) in
                if (granted) {
                    //第一次用户接受
                    if let tmp = handle {
                        tmp()
                    }
                }else{
                    //用户拒绝 *** 问题在这里,如果第一次用户拒绝了,回调并不在主线程。(注意,此时的case分支在用户并未决定里)
                    if let tmp = limitHandle {
                        dispatch_async(dispatch_get_main_queue(), {
                            tmp()
                        })
                    }
                }
            })
        case .Restricted: // 无法访问
            dLog("没有设备")
        case .Denied: // 用户拒绝
            if let tmp = limitHandle {
                dispatch_async(dispatch_get_main_queue(), {
                    tmp()
                })
            }
        case .Authorized: // 开启授权
            if let tmp = handle {
                tmp()
            }
        }

This problem can be solved by placing the callback on the main thread where the user first decides whether to agree to use the album.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template