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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -