filesystems - how can i back again to main thread after finish saving images and videos in swift? -
please have save image , videos in document directory saving on background thread images , videos problem how can know saving finish image , videos or image , video ? because don't know how can detect the operation finish?
the following code :
dispatchqueue.global(qos: .background).async { (_,asset) in self.dictionaryofassets.enumerated() { if asset.value.mediatype == .image { let getnumberofphotosinthumbfolder = dealwithfilesystem.fetchnumberoffilesinfolder(foldername: foldername) let imagethumbpath = dealwithfilesystem.fetchfoldername(foldername: foldername)?.appendingpathcomponent("image \(getnumberofphotosinthumbfolder!).png") let fetchoption = phimagerequestoptions() fetchoption.issynchronous = true fetchoption.deliverymode = .highqualityformat fetchoption.resizemode = .exact phimagemanager.default().requestimage(for: asset.value, targetsize: cgsize(width:100,height:100), contentmode: .aspectfill, options: fetchoption, resulthandler: { (img, info) in if let convertimage = uiimagepngrepresentation(img!) { try! convertimage.write(to: imagethumbpath!) } }) // save image full size let imagefullpath = dealwithfilesystem.fetchfoldername(foldername: foldername + ".xcvg")?.appendingpathcomponent("image \(getnumberofphotosinthumbfolder!).png") phimagemanager.default().requestimagedata(for: asset.value, options: fetchoption, resulthandler: { (data, _, _, nil) in try! data?.write(to: imagefullpath!) }) // end image saving }else if asset.value.mediatype == .video { let getnumberofphotosinthumbfolder = dealwithfilesystem.fetchnumberoffilesinfolder(foldername: foldername) let imagethumbpath = dealwithfilesystem.fetchfoldername(foldername: foldername)?.appendingpathcomponent("video \(getnumberofphotosinthumbfolder!).jpg") let fetchoption = phimagerequestoptions() fetchoption.issynchronous = true fetchoption.resizemode = .exact fetchoption.deliverymode = .highqualityformat phimagemanager.default().requestimage(for: asset.value, targetsize: cgsize(width:100,height:100), contentmode: .aspectfill, options: fetchoption, resulthandler: { (img, info) in if let convert = uiimagepngrepresentation(img!) { try! convert.write(to: imagethumbpath!) } }) let videofilepath = dealwithfilesystem.fetchfoldername(foldername: foldername + ".xcvg")?.appendingpathcomponent("video \(getnumberofphotosinthumbfolder!).mp4") phimagemanager.default().requestavasset(forvideo: asset.value, options: nil, resulthandler: { (avasset, avaudio, info) in let getasseturl = avasset as! avurlasset if let convertvideo = nsdata(contentsof: getasseturl.url) { convertvideo.write(to: videofilepath!, atomically: true) krprogresshud.show() }// end convert image })// end save video }// end if statment }// end loop }// end background thread block
thanks advance
Comments
Post a Comment