这是我下面的实际代码 . 它总是下载第一张图片,但是给出了"Camera is busy or the command is not supported in the camera's current state" . 我尝试了How to programmatically download Images from drone using the IOS DJI-SDK提出的解决方案

在过去的10天里,我一直在努力解决这个问题,并试图在异步队列等中触发各种组合,但没有成功 . 虽然DJI样本有很多代码,但它们都专注于单个下载和预览等,但不是整个原始数据,只有多个文件下载 . 非常感谢任何帮助 .

func downLoad(){
     guard let drone = (DJISDKManager.product() as? DJIAircraft) else {
            testAlert(viewC: self, title: "Message", msg: "Unable to detect Drone", buttonText: "Dismiss")
            return
        }
        // Get camera on drone
        guard  let camera: DJICamera = drone.camera else {
            testAlert(viewC: self, title: "Message", msg: "Unable to detect Camera in initDownload()", buttonText: "Dismiss")
            return
        }
        // check if we can download images with the product
        if !camera.isMediaDownloadModeSupported() {
            testAlert(viewC: self, title: "Message", msg: "Product does not support media download mode", buttonText: "Dismiss")
            return
        }
        camera.setMode( .mediaDownload, withCompletion: {(error) in

            if error != nil {
                self.testAlert(viewC: self, title: "Message", msg: "Error \(error!.localizedDescription)", buttonText: "Dismiss")
            } else {
                // get the media manager from the drone to gain access to the files
                let manager = camera.mediaManager!

                manager.refreshFileList(of: DJICameraStorageLocation.sdCard, withCompletion:  { (error) in
                    if error != nil {

Error here after first download

self.testAlert(viewC: self, title: "Message", msg: "Error refreshing list: \(error!.localizedDescription)", buttonText: "Dismiss")
                    }else {

                        // get list of files
                        guard let files = manager.sdCardFileListSnapshot() else {
                            self.testAlert(viewC: self, title: "Message", msg: "No files to download", buttonText: "Dismiss")
                            return
                        }
                        self.downloadImages(files: files, completion: { images in
                            //process images 
                           self.testAlert(viewC: self, title: "Message", msg: "Successfully downloaded all images and count \(images.count)", buttonText: "Dismiss")

                        })//end of downloadImages

                    }// end of else
                }) // end of file-refresh block
            } // end of if else
        })// end of camera setMode block
    }

    func downloadImages(files: [DJIMediaFile], completion: @escaping ([String]) -> Void){
        func downloadNextImage( files: [DJIMediaFile], index: Int = 0, downloadedFileUrls: [String] = []) {
            // stop when we reach the end of the list

            if (index >= files.count - 1)  {
                completion(downloadedFileUrls)
                return
            }
            else {
                var imageData = Data()
                var file = files[index]
                let isPhoto = file.mediaType == DJIMediaType.JPEG || file.mediaType == DJIMediaType.TIFF;

                var previousOffset: UInt = 0

                file.fetchData(withOffset: previousOffset, update: DispatchQueue.main, update: {(_ data: Data?, _ isComplete: Bool, _ error: Error?) -> Void in
                    if let error = error {
                        self.testAlert(viewC: self, title: "Error", msg: "File index : \(index) previousOffset : \(previousOffset) name: \(file.fileName) error : \(error)", buttonText: "Dismiss")
                    }
                    else {
                        imageData.append(data!)
                        previousOffset =  previousOffset + UInt((data?.count)!);
                        if isComplete {
                            if let image = UIImage(data: imageData) {
                                var imageUrl : String = ""
                                if(isPhoto){
                                    imageUrl = saveFile(imag)
                                }else //video
                                {
                                    //process video
                                }
                                downloadNextImage( files: files, index: (index + 1), downloadedFileUrls: downloadedFileUrls + [imageUrl])
                            }// If image
                        } //If complete
                    }// no eroor
                }) // end of filedata fetch
            }   // end of else statement
        }
        // start the recursive function
        downloadNextImage( files: files, index: 0)
    }