ios - How to write GIF image from url to documents directory -
i have gif image url , want download documents directory, have tried using
if let gifimagedata = uiimagepngrepresentation(image!) { try gifimagedata.write(to: fileurl, options: .atomic) }
and
if let jpegimagedata = uiimagejpegrepresentation(image!, 1.0) { try jpegimagedata.write(to: fileurl, options: .atomic) }
but image saving single png/jpg image , not animated gif
any solution this?
problem filename, try this:
//the url save let yoururl = nsurl(string: "http://somewebsite.com/somefile.gif") //create url request let urlrequest = nsurlrequest(url: yoururl!) //get data let thedata = nsurlconnection.sendsynchronousrequest(urlrequest, returningresponse: nil, error: nil) //get local docs directory , append local filename. var docurl = (nsfilemanager.defaultmanager().urlsfordirectory(.documentdirectory, indomains: .userdomainmask)).last as? nsurl docurl = docurl?.urlbyappendingpathcomponent( "myfilename.gif") //lastly, write file disk. thedata?.writetourl(docurl!, atomically: true)
Comments
Post a Comment