ios - AVAssetExportSession in share extension -
i'm trying use avassetexportsession on video selected in share extension , getting
error domain=nsurlerrordomain code=-3000 "cannot create file" userinfo={nslocalizeddescription=cannot create file, nsunderlyingerror=0x14811fdb0 {error domain=nsosstatuserrordomain code=-12124 "(null)"}}
but can create file manually @ same nsurl without error. here function i'm using
func reencodevideo() { let videoasset = avurlasset(url: video.url) let videotrack = videoasset.trackswithmediatype(avmediatypevideo)[0] avassettrack print(videotrack.estimateddatarate) let exportsession = avassetexportsession(asset: videoasset, presetname: avassetexportpreset1920x1080) guard let outputurl = uploadablefileurl else { return } let filemanager = nsfilemanager.defaultmanager() // let created = filemanager.createfileatpath(outputurl.path!, contents: nil, attributes: nil) if let path = outputurl.path filemanager.fileexistsatpath(path) { print("file exists") } { try filemanager.removeitematurl(outputurl) print("deleted") } catch { print(error) } exportsession?.outputurl = outputurl exportsession?.outputfiletype = avfiletypequicktimemovie exportsession?.exportasynchronouslywithcompletionhandler{ print(exportsession?.status) } } private var uploadablefileurl: nsurl? { guard let tempfilename = video.url.lastpathcomponent else { return nil } let filemanager = nsfilemanager.defaultmanager() guard let containerurl = filemanager.containerurlforsecurityapplicationgroupidentifier(constants.appgroupidentifier) else { return nil } return containerurl.urlbyappendingpathcomponent("videofile.mov") }
i've created file in same directory, avassetexportsession returns error there. ideas i'm doing wrong?
i've tried using avassetreader
, avassetwriter
, , avassetwriter
returns same error when trying start. encode process completes if i'm using documents directory , fails when using shared app group container.
you're issue might related use of document folder , icloud sync. see https://forums.developer.apple.com/message/77495#77495
if :
guard let containerurl = filemanager.containerurlforsecurityapplicationgroupidentifier(constants.appgroupidentifier) else { return nil } let libraryurl = containerurl.urlbyappendingpathcomponent("library", isdirectory: true) let cachesurl = libraryurl.urlbyappendingpathcomponent("caches", isdirectory: true) return cachesurl.urlbyappendingpathcomponent("videofile.mov")
Comments
Post a Comment