简体   繁体   中英

Make Loading UIWebView faster by saving html page

I am making a hybrid iOS app . The native part of the app redirects to UIWebView that dynamic data. Is it possible to cache this data locally to make transition to the Webpage faster?

Please try this one:

NSData *urlData;
NSString *baseURLString =  @"mysite.com";
NSString *urlString = [baseURLString stringByAppendingPathComponent:@"myfile"];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 10.0]; 
NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:nil]; 

if (connection)
{ 
   urlData = [NSURLConnection sendSynchronousRequest: request];

   NSString *htmlString = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
   [webView loadHTMLString:htmlString baseURL:baseURLString];
   [htmlString release];
}

[connection release];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM