Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift UIImagePickerController在iCloud中出现照片问题并允许编辑_Swift_Uiimagepickercontroller_Icloud - Fatal编程技术网

Swift UIImagePickerController在iCloud中出现照片问题并允许编辑

Swift UIImagePickerController在iCloud中出现照片问题并允许编辑,swift,uiimagepickercontroller,icloud,Swift,Uiimagepickercontroller,Icloud,我需要帮助。 我使用UIImagePickerController加载化身。我可以用照相机拍照,你可以选择一张照片。 我的照片部分存储在iCloud中,只有预览部分存储在设备上,部分存储在本地。 当选择本地照片或从相机,我们进入区域选择屏幕,图像裁剪。 因此,如果照片存储在iCloud中,则会发生以下情况: 我选择一张照片,单击“完成”-窗口关闭,但没有照片 我的代码: 从库中选择照片的代码 func openMediaDialog() { PHPhotoLibrary

我需要帮助。 我使用UIImagePickerController加载化身。我可以用照相机拍照,你可以选择一张照片。 我的照片部分存储在iCloud中,只有预览部分存储在设备上,部分存储在本地。 当选择本地照片或从相机,我们进入区域选择屏幕,图像裁剪。 因此,如果照片存储在iCloud中,则会发生以下情况:

我选择一张照片,单击“完成”-窗口关闭,但没有照片

我的代码:

从库中选择照片的代码

func openMediaDialog() {
    
        PHPhotoLibrary.requestAuthorization({status in
                if status == .authorized{
                    DispatchQueue.main.async {
                        self.imagePicker.sourceType = UIImagePickerController.SourceType.photoLibrary
                        //self.imagePicker.navigationItem.setHidesBackButton(false, animated: false)
                        //If you dont want to edit the photo then you can set allowsEditing to false
                        self.imagePicker.allowsEditing = true
                        self.imagePicker.delegate = self
                        self.present(self.imagePicker, animated: true, completion: nil)
                    }
                    
                } else if status == .denied {
                
                    self.alertCameraAccessNeeded(title: "Необходим доступ к фото!", message: "Для загрузки аватара необходим доступ к фото. Разрешить?")
                }
        })
    
    
}
代表:

override func imagePickerController(_ picker: UIImagePickerController,
                           didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    /*
     Get the image from the info dictionary.
     If no need to edit the photo, use `UIImagePickerControllerOriginalImage`
     instead of `UIImagePickerControllerEditedImage`
     */
    
    guard let selectedImage = info[UIImagePickerController.InfoKey.editedImage] as? UIImage else {
        fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
        self.view.makeToast("Проблема с выбором изображения")
        
    }
    
    
    
    print(selectedImage)
....
下一步-上传图像


我要求您告诉我如何确保照片从icloud下载,根据需要进行裁剪,并根据通常情况进一步加载到服务器。

如果您在icloud上的照片。。使用此功能获取照片

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        // it will be loaded asynchronously
        loadImageFromPicker(info: info)
        picker.dismiss(animated: true, completion: nil)
        self.presentingViewController?.dismiss(animated: true, completion: nil)
    }

    private func loadImageFromPicker(info: [UIImagePickerController.InfoKey : Any]) {
        guard let phAsset = info[.phAsset] as? PHAsset else {
            return
        }
       
        // size doesn't matter, because resizeMode = .none
        let size = CGSize(width: 32, height: 32)
        let options = PHImageRequestOptions()
        options.version = .original
        options.deliveryMode = .highQualityFormat
        options.resizeMode = .none
        options.isNetworkAccessAllowed = true
        PHImageManager.default().requestImage(for: phAsset, targetSize: size, contentMode: .aspectFit, options: options) { [weak self] (image, info) in
            if let s = self, let image = image {
                // use this image
            }
        }
    }