[英]SDK DJI download photo in swift
I am simply attempting to download the latest access the feed from my DJI drone and convert the feed into a UIImage. 我只是试图从我的DJI无人机下载最新的访问提要,并将提要转换为UIImage。 The easiest way i thought this could be done is take a photo, then promptly afterwards download the latest photo from the storage.
我认为可以完成的最简单方法是拍摄照片,然后迅速从存储设备中下载最新照片。 I will add the download from storage code below.
我将在下面的存储代码中添加下载内容。 Is this the easiest way?
这是最简单的方法吗? I have been receiving this error code -
我一直收到此错误代码-
Settings parameters operation failed. (Code : -1007)
I've researched but couldn't find what this meant - The DJI docs are limited to pretty much all obj-c. 我已经研究过了,但找不到它的意思-DJI文档仅限于几乎所有obj-c。 Here the code -
这里的代码-
@IBAction func download(_ sender: UIButton) {
let camera = self.fetchCamera()
// switch camera mode to allow for media downloads
camera?.setMode(DJICameraMode.mediaDownload, withCompletion: {(error) in
if error != nil {
self.status.text="\(error!.localizedDescription)"
}
else {
// get the media manager from the drone to gain access to the files
let manager = camera!.mediaManager!
if error != nil {
self.status.text = "State: \(manager.sdCardFileListState.rawValue)"
self.status.text = "Error refreshing list: \(error)"
}
else {
print("Refreshed file list")
print("State: \(manager.sdCardFileListState.rawValue)")
guard let files = manager.sdCardFileListSnapshot() else {
self.status.text = ("No files to download")
return
}
self.status.text = "There are files to download"
var images: [UIImage] = []
for file in files {
if file.mediaType == .JPEG {
self.status.text = ("Time created: \(file.timeCreated)")
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
file.fetchData(withOffset: 0, update: DispatchQueue.main, update: {(_ data: Data?, _ isComplete: Bool, _ error: Error?) -> Void in
if error != nil {
self.status.text = "State: \(manager.sdCardFileListState.rawValue)"
self.status.text = "Error downloading photo: \(error!)"
}
else {
// unwrap downloaded data and create image
if let data = data, let downloadedImage = UIImage(data: data) {
self.status.text = "Image was downloaded!"
images.append( downloadedImage )
}
}
}) // end of filedata fetch
}
}
} // end of loop
}
}
})// end of camera setMode block
}`
Any help would be greatly appreciated - Thanks 任何帮助将不胜感激-谢谢
@IBAction func download(_ sender: UIButton) {
let camera = self.fetchCamera()
// switch camera mode to allow for media downloads
camera?.setMode(DJICameraMode.mediaDownload, withCompletion: {(error) in
if error != nil {
self.status.text="\(error!.localizedDescription)"
}
else {
// get the media manager from the drone to gain access to the files
let manager = camera!.mediaManager!
if error != nil {
self.status.text = "State: \(manager.sdCardFileListState.rawValue)"
self.status.text = "Error refreshing list: \(error)"
}
else {
print("Refreshed file list")
print("State: \(manager.sdCardFileListState.rawValue)")
while(manager.internalStorageFileListState != .UpToDate) {
// Do nothing...
}
guard let files = manager.sdCardFileListSnapshot() else {
self.status.text = ("No files to download")
return
}
self.status.text = "There are files to download"
var images: [UIImage] = []
for file in files {
if file.mediaType == .JPEG {
self.status.text = ("Time created: \(file.timeCreated)")
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
file.fetchData(withOffset: 0, update: DispatchQueue.main, update: {(_ data: Data?, _ isComplete: Bool, _ error: Error?) -> Void in
if error != nil {
self.status.text = "State: \(manager.sdCardFileListState.rawValue)"
self.status.text = "Error downloading photo: \(error!)"
}
else {
// unwrap downloaded data and create image
if let data = data, let downloadedImage = UIImage(data: data) {
self.status.text = "Image was downloaded!"
images.append( downloadedImage )
}
}
}) // end of filedata fetch
}
}
} // end of loop
}
}
})// end of camera setMode block
}
Why dont you override the callback for a "new file generated" and then download the file there 为什么不重写“生成的新文件”的回调,然后在那里下载文件
func camera(_ camera: DJICamera, didGenerateNewMediaFile newMedia: DJIMediaFile) {
newMedia.fetchData(withOffset: 0, update: DispatchQueue.main, update: {(_ data: Data?, _ isComplete: Bool, _ error: Error?) -> Void in
if error != nil {
self.status.text = "State: \(manager.sdCardFileListState.rawValue)"
self.status.text = "Error downloading photo: \(error!)"
}
else {
// unwrap downloaded data and create image
if let data = data, let downloadedImage = UIImage(data: data) {
self.status.text = "Image was downloaded!"
images.append( downloadedImage )
}
}
}) // end of filedata fetch
}
You will have to implement the "DJICameraDelegate" class and set the delegate in your ViewController. 您将必须实现“ DJICameraDelegate”类,并在ViewController中设置委托。 Hope this helps!
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.