ios - How to Upload video files in background? -
i doing app in need upload videos taken iphone camera , upload server. when app in foreground video gets uploaded don't know how in background when app inactive. used afnetworking multipart data upload. here code tried 
var task:nsurlsessionuploadtask! let filepicker_base_url = "my server url" var isuploading : bool = false var videopath : string! func upload(dictmain: nsmutabledictionary) {     isuploading = true     let uuid =  nsuuid().uuidstring + "-" + (getuserid().description)     let request = afhttprequestserializer().multipartformrequestwithmethod("post", urlstring: filepicker_base_url, parameters: nil, constructingbodywithblock: { (fromdata) in          {             try fromdata.appendpartwithfileurl(nsurl(fileurlwithpath: videopath) , name: "fileupload", filename: uuid, mimetype: "video/quicktime")         }catch{             print(error)         }         }, error: nil)      let manager:afurlsessionmanager = afurlsessionmanager(sessionconfiguration: nsurlsessionconfiguration.backgroundsessionconfigurationwithidentifier("your video uploading"));      task = manager.uploadtaskwithstreamedrequest(request, progress: nil , completionhandler: { (response, responseobject, error) in             nslog("resposne object: \(responseobject)")             post(dictmain,response: responseobject!)     })     task.resume()     } also don't know how know upload progress. tried use following block in progress parameter
 { (progress) in     print("\((progress))")  } but not work complier shows error  cannot convert value of type '(_) -> _' expected argument type 'autoreleasingunsafemutablepointer<nsprogress?>' (aka 'autoreleasingunsafemutablepointer<optional<nsprogress>>')
could 1 share snippet works. googled there very few basic tutorials on nsurlsession.uploadtaskwithstreamedrequest , of them tried didn't work on swift 2.2
i using xcode 7.3 swift 2.2
points know:
- background upload works file paths , not - nsdata. took video url path- uiimagepickercontrollerfunction- func video(videopath: nsstring, didfinishsavingwitherror error: nserror?, contextinfo info: anyobject)
- to background file transfer have enable them in - target->- capabilities->- background modes->- background fetch
- must set session manager - nsurlsessionconfiguration.backgroundsessionconfigurationwithidentifier(""). don't know why , identifier being used.
i know long post. if answered surely helpful many developers.
 
 
  
Comments
Post a Comment