@IBAction func captureAction(sender: UIButton) {
let camera
JICamera? = self.fetchCamera()
if(camera != nil){
camera!.startShootPhoto(.Single, withCompletion: { (error:NSError?) in
if( error != nil){
self.showAlertWithMessage("Take Photo Error", message: error!.description)
}
})
}
}
2 拍照成功后,我定义一个函数setCameraModeMediaDownload(),用来设置DJICamera的模式为.MediaDownload,然后开始读取sd的文件列表,将刚刚拍的图片下载到手机。即我在DJCameraDelegate的代理函数中实现:
func camera(camera: DJICamera, didGenerateNewMediaFile newMedia: DJIMedia)
{
self.setCameraModeMediaDownload()
self.startFetchMedia()//调用了
self.fetchPreviewImage()
self.setCameraModeShootPhoto()
}
运行时发现, self.setCameraModeMediaDownload() 并没有改变相机的模式,
并且self.startFetchMedia() 后 也不能自动的去执行self.fetchPreviewImage()这个函数。
可不可以帮我分析一下,我的思路哪里出错了?该如何实现精灵3拍照后自动下载的功能呢?
相关的4个函数的实现如下:
func setCameraModeShootPhoto()
{
let camera
JICamera? = self.fetchCamera()
if (camera == nil ){
self.showAlertWithMessage("Message", message: "No Camera")
}else{
camera!.setCameraMode(.ShootPhoto, withCompletion: { (error:NSError?) in
if(error != nil){
self.showAlertWithMessage("Set ShootPhoto Mode Error ", message: error!.description)
}
})
}
}
func setCameraModeMediaDownload()
{
let camera
JICamera? = self.fetchCamera()
if (camera == nil ){
self.showAlertWithMessage("Message", message: "No Camera")
}else{
camera!.setCameraMode(.MediaDownload, withCompletion: { (error:NSError?) in
if(error != nil){
self.showAlertWithMessage("Set MediaDownload Mode Error ", message: error!.description)
}
})
}
}
func startFetchMedia()
{
let camera
JICamera? = self.fetchCamera()
if camera != nil {
camera!.mediaManager.fetchMediaListWithCompletion( {(mediaList:[DJIMedia]?, error: NSError?) -> Void in
if error != nil {
self.showAlertWithMessage("FethcMedia Error", message: error!.description)
}else {
print("startFetchMedia")
for media
JIMedia in mediaList! {
if media.mediaType == DJIMediaType.JPEG {
self.imageMedia = media
}
}
}
})
}
}
func fetchPreviewImage()
{
self.imageMedia?.fetchPreviewImageWithCompletion({ (image:UIImage, error:NSError?) in
if error != nil{
self.showAlertWithMessage("FetchPreviewImage Error", message: error!.description)
}else{
print("fetchPreviewImage")
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil)
print(image)
}
})
}