ios - Open file with quicklook(download from url) -


now want open file(ex:.docx,.txt,.ppt,.png) quicklook, download 2 files own server,i want open first file,but i'm not sure if there successful download, , don't know how use quick framework,and

type 'bddeatilviewcontroller' not conform protocol 'qlpreviewcontrollerdatasource'

,but have added protocol of qlpreviewcontrollerdatasource,can me it? here codes,thanks!

class bddeatilviewcontroller:uiviewcontroller,qlpreviewcontrollerdatasource {       let quicklookcontroller = qlpreviewcontroller()      var fileurlarray:[string] = []     var urlarray : [url] = []      override func viewdidload() {         super.viewdidload()         addurltofile(filearray: bulletinboard.attachments!)         stringtourl(stringarray: fileurlarray)          quicklookcontroller.datasource = self     }      @ibaction func openfile(_ sender: any) {          downloadfile(url: urlarray, atindex: 0)         quicklookcontroller.currentpreviewitemindex = 0         navigationcontroller?.pushviewcontroller(quicklookcontroller, animated: true)      }      //add profix url file     func addurltofile(filearray:array<string>)  {         file in filearray {             var newurl:string = ""             newurl = "http://163.18.22.78:81/api/donwload/" + file             fileurlarray.append(newurl)         }     }      //convert string array url array     func stringtourl(stringarray:array<string>) {         in stringarray {             let url = url(string: i)             urlarray.append(url!)         }     }      //download file server     func downloadfile(url:[url],atindex:int) {          let requesturl = url[atindex]         let urlrequest: nsmutableurlrequest = nsmutableurlrequest(url: requesturl)         let session = urlsession.shared         let task = session.datatask(with: urlrequest urlrequest) {             (data, response, error) -> void in             if let httpresponse = response as? httpurlresponse {                 let statuscode = httpresponse.statuscode                 if (statuscode == 200) || ((statuscode == 204)) {                    print("everyone fine, file downloaded successfully.")                 }             }         }         task.resume()     }      func numberofpreviewitemsinpreviewcontroller(controller: qlpreviewcontroller) -> int {         return urlarray.count     }      func previewcontroller(_ controller: qlpreviewcontroller, previewitemat index: int) -> qlpreviewitem {         return urlarray[index] qlpreviewitem     }  } 

you're giving quicklook elements in urlarray http:// urls. need give file urls quick not download items itself. use nsurlsessiondownloadtask instead of nsurlsessiondatatask download file disk, not data object, , give quick downloaded file's url.

additionally, devanshu saini right: you're using wrong qlpreviewcontroller delegate method signatures.

you want these:

func numberofpreviewitems(in: qlpreviewcontroller) func previewcontroller(qlpreviewcontroller, previewitemat: int) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -