objective c - iOS PHPhotoLibrary cannot save video to Camera Roll -


i'm trying save video file application's documents folder device's camera roll. error occurs when albumchangerequest tries copy asset camera roll. fails copy file album, , gives error message (domain=nscocoaerrordomain code=-1 "(null)", operation couldn't completed). used deprecated method (writevideoatpathtosavedphotosalbum) copy video, , used same file path, problem should not file path url.

...  phphotolibrary *photolibrary = [phphotolibrary sharedphotolibrary]; nsurl *filepathurl = [nsurl fileurlwithpath:videopath isdirectory:no]; __block nsstring* asseturl = nil;  phfetchresult *fetchresult = [phassetcollection fetchassetcollectionswithtype:phassetcollectiontypesmartalbum subtype:phassetcollectionsubtypesmartalbumuserlibrary options:nil]; phassetcollection* album = fetchresult.firstobject;  if (album) {     [photolibrary performchanges:^{         phassetchangerequest *assetchangerequest = [phassetchangerequest creationrequestforassetfromvideoatfileurl:filepathurl];         phassetcollectionchangerequest *albumchangerequest = [phassetcollectionchangerequest changerequestforassetcollection:album];          phobjectplaceholder *assetchangeplaceholder = assetchangerequest.placeholderforcreatedasset;          asseturl = [assetchangeplaceholder localidentifier];         [albumchangerequest addassets:@[assetchangeplaceholder]];     } completionhandler:^(bool success, nserror * error) {         if ( success ){             nsstring* urlsubstr = [asseturl substringtoindex:36];              // handle result asset id in urlsubstr.         } else {                             // copy failed.         }     }]; }  ... 

swift 3.0

let photolibrary = phphotolibrary.shared() let filepathurl = url(fileurlwithpath: videopath, isdirectory: false) var asseturl: string! = nil  let fetchresult = phassetcollection.fetchassetcollections(with: phassetcollectiontype.smartalbum, subtype: phassetcollectionsubtype.smartalbumuserlibrary, options: nil)  if  let album = fetchresult.firstobject {     photolibrary.performchanges({           if  let assetchangerequest = phassetchangerequest.creationrequestforassetfromvideo(atfileurl: outputfileurl),             let albumchangerequest = phassetcollectionchangerequest(for: album),             let assetchangeplaceholder = assetchangerequest.placeholderforcreatedasset {                 asseturl = assetchangeplaceholder.localidentifier                 albumchangerequest.addassets(assetchangeplaceholder as! nsfastenumeration)             }          }, completionhandler: { (succeed, error) in              if  succeed {                 let index = asseturl.index(asseturl.startindex, offsetby: 36)                 let urlsubstr = asseturl.substring(to: index)             }             else {                 // copy failed             }          })     } } 


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -