swift 3在使用相机时请求许可

时间:2017-10-09 07:01:31

标签: ios swift3 permissions camera plist

我已经阅读了很多关于这个问题的文章,这些文章只在plist上增加了代码行:

Key     :  Privacy - Camera Usage Description   
Value   :  $(PRODUCT_NAME) camera use

但我仍有同样的问题

错误消息

  

'尝试在没有相机的设备上开始扫描。在调用之前检查requestCameraPermissionWithSuccess:方法   startScanningWithResultBlock:

似乎它仍然没有在应用程序上使用相机的权限

但实际上我们如何才能在iOS设备上获得相机访问权限?

这是我的代码

    MTBBarcodeScanner.requestCameraPermission(success: { success in
        if success {
            do {
                try self.scanner?.startScanning(resultBlock: { codes in
                    if let codes = codes {
                        for code in codes {
                            let stringValue = code.stringValue!
                            print("Found code: \(stringValue)")

                            if (stringValue != nil)
                            { ... }

                                    })
                                }))
                                self.present(alert, animated: true, completion: nil)
                            }
                        }
                    }
                })
            } catch {
                NSLog("Unable to start scanning")
            }
        } else {
            UIAlertView(title: "Scanning Unavailable", message: "This app does not have permission to access the camera", delegate: nil, cancelButtonTitle: nil, otherButtonTitles: "Ok").show()
        }
    })

1 个答案:

答案 0 :(得分:0)

以便访问设备'相机你必须提供相机使用说明。 您可以在Info.plist文件中执行此操作。

只需点击" +"它旁边的图标"信息属性列表"并输入Privacy - Camera Usage Description。 然后作为一个值提供一个简短的使用信息,例如"我们需要访问才能扫描条形码。"

希望这有帮助。

相关问题