objective c - How to fetch a webpage in a quicklook plugin? -


my plugin has make google request , display page's html content.
have been able display html far, though quicklook supposed support network access!

kng attempted fetch pages (building .webloc viewer), no luck, said in readme

quicklook in lion project attempted do.

i have mountain lion , have applied similar patterns, shown below, still no luck. nobody on web seem have ever tried access url quicklook plugin; besides undocumented webloc plugin provided apple. moreover, quicklook programing guide 4 years old.

what have tried:

osstatus generatepreviewforurl(void *thisinterface,                                qlpreviewrequestref preview,                                cfurlref url,                                cfstringref contenttypeuti,                                cfdictionaryref options) {     if (qlpreviewrequestiscancelled(preview))         return noerr;      //// fetch web page      nsdata *data;     nserror *err;      /// attempt 0: static html -- ok     //nsstring *html = @"<html><body><h1>it works!</h1></body></html>";      /// attempt 1: datawithcontentsofurl -- ko     data = [nsdata datawithcontentsofurl:[nsurl urlwithstring:@"http://google.com/"] options:nsdatareadinguncached error:&err];      /// attempt 2: nsurlconnection -- ko     //nsurlrequest *urlrequest = [nsurlrequest requestwithurl:[nsurl urlwithstring:@"http://google.com/"]];     //nsurlresponse *response;     //data = [nsurlconnection sendsynchronousrequest:urlrequest returningresponse:&response error:&err];       // builds /users/pete/out.txt on error     nsstring *html = [[nsstring alloc] initwithdata:(nsdata *)data encoding:nsutf8stringencoding];     [err.description writetofile:@"/users/pete/out.txt" atomically:yes encoding:nsutf8stringencoding error:nil];      //// display html      nsmutabledictionary *props;     [props setobject:@"utf-8" forkey:(nsstring *)kqlpreviewpropertytextencodingnamekey];     [props setobject:@"text/html" forkey:(nsstring *)kqlpreviewpropertymimetypekey];      qlpreviewrequestsetdatarepresentation(preview,                                           (__bridge cfdataref)[html datausingencoding:nsutf8stringencoding],                                           kuttypehtml,                                           (__bridge cfdictionaryref)props);     return noerr; } 

the complete code & environment can found here

for security reasons, quick plug-ins not allowed network requests. in fact, plug-in sandboxed , should allowed access file trying preview (in addition frameworks plug-in needs, of course).


Comments