在WKWebView中使用Swift 4请求图书馆许可

时间:2018-08-14 01:39:43

标签: ios swift

我有一个想要从wkwebview上的库中检索照片的功能。但是,当我选择图像时,尽管我已在info.split中声明了该图像,但该应用程序并不要求提供库许可。选择照片时,我是否可以让应用程序要求图书馆许可?

1 个答案:

答案 0 :(得分:1)

您需要正式征求许可,以便用户有机会决定是否允许您的应用访问照片。 有很多方法可以做到这一点,但这是一个示例:

func configureGalleryAccess() {
    print("configure called")
    let status = PHPhotoLibrary.authorizationStatus()
    if status == .authorized {
        print("app was previously authorized")
        self.postAuthorizationLoadController()
    } else {
        PHPhotoLibrary.requestAuthorization({(_ status: PHAuthorizationStatus) -> Void in
            print("configure completion called")
            switch status {
            case .authorized:
                print("PHAuthorizationStatusAuthorized")
                self.postAuthorizationLoadController()
            case .denied:
                print("PHAuthorizationStatusDenied")
            case .notDetermined:
                print("PHAuthorizationStatusNotDetermined")
            case .restricted:
                print("PHAuthorizationStatusRestricted")
            }
        })
    }
}

/// Called after permission has been granted.
func postAuthorizationLoadController() { }