ios - UIWebView contents preload using NSURLConnection -


i'm developing ios app has 2 vcs, mapvc(using google map sdk) , webvc. selecting annotation on mapvc, transition webvc corresponding webpage openned. loadrequest method in viewdidload of webview slow wait.

so want preload web data when selecting pin on mapview, , hand on preloaded data webvc using loaddata method.

but webvc displays text, no images no css. should preload full html/css/images? advice appreciated. in advance.

my current source code follows.

// --- mapviewcontroller --- - (bool)mapview:(gmsmapview *)mapview didtapmarker:(gmsmarker *)marker {     nsurl   *url = [nsurl urlwithstring:@"(target url)"];     nsurlrequest *urlrequest = [nsurlrequest requestwithurl:url                                 cachepolicy:nsurlrequestuseprotocolcachepolicy                                         timeoutinterval:60.0];     receiveddata = [nsmutabledata datawithcapacity:0];     nsurlconnection *urlconnection;     urlconnection = [nsurlconnection connectionwithrequest:urlrequest delegate:self];     if (!urlconnection) {         receiveddata = nil;     } }  - (void)connection:(nsurlconnection *)connection didreceiveresponse:(nsurlresponse *)response {     [receiveddata setlength:0]; }  - (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data {     [receiveddata appenddata:data]; }  - (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error {     receiveddata = nil; }  - (void)connectiondidfinishloading:(nsurlconnection *)connection { }  - (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {     if ([[segue identifier] isequaltostring:@"showweb"]) {         webviewcontroller   *webviewcontroller = [segue destinationviewcontroller];         webviewcontroller.preloadeddata = receiveddata;     } }  // --- webviewcontroller ---     - (void)viewdidload {     [super viewdidload];     self.webview.delegate = self;     [self.webview loaddata:self.preloadeddata                   mimetype:@"text/html"           textencodingname:@"utf-8"                    baseurl:nil]; } 

take @ asiwebpagerequest. allows download of entire web page, including resources.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -