ios - AFHTTPSessionManager posting video swift -
i trying upload video in background using afnetworking > afhttpsessionmanager post method. want conitune uploading if app suspended. error while executing code, logs no error, , points in code. tried every solution available on other posts regarding scenario, couldn't working. plesae check code below , suggest me solution or link me somewhere make work
{ let urlstring = baseurl + weblinks.post let appid = nsbundle.mainbundle().bundleidentifier let config = nsurlsessionconfiguration.backgroundsessionconfigurationwithidentifier(appid!)// crashes //let config = nsurlsessionconfiguration.defaultsessionconfiguration()//doesnt work in background config.allowscellularaccess = true config.timeoutintervalforrequest = nstimeinterval(999) config.timeoutintervalforresource = nstimeinterval(999) let manager = afhttpsessionmanager(baseurl: nsurl(string: urlstring), sessionconfiguration: config) manager.responseserializer.acceptablecontenttypes = nsset(object: "application/json") set<nsobject> manager.requestserializer.setvalue(persistencemanager.sharedinstance.accesstoken, forhttpheaderfield: "authorization") let param = [ "subject":subject, ] print(urlstring) manager.post(urlstring, parameters: param, constructingbodywithblock: { (formdata) -> void in if var imagetoupload = image { imagetoupload = imagetoupload.resizeimage(1200) let imagedata = uiimagejpegrepresentation(imagetoupload, 0.9); formdata.appendpartwithfiledata(imagedata, name: "post_image", filename: "picture.jpg", mimetype: "image/jpeg") } if let videourl = video { //let videodata = nsdata(contentsofurl: videourl) //formdata.appendpartwithfiledata(videodata, name: "post_video", filename: "video.mp4", mimetype: "video/quicktime") do{ try formdata.appendpartwithfileurl(videourl, name: "post_video", filename: "video.mp4", mimetype: "video/quicktime") }catch{ print("failed attach video") } } }, success: { (nsurlsessiondatatask, response) -> void in print (response) }) { (nsurlsessiondatatask, error) -> void in print (error.localizeddescription) } }
Comments
Post a Comment