我正在制作hybrid iOS app
。应用的原生部分会重定向到UIWebView
动态数据。是否可以在本地缓存此数据以更快地转换到网页?
答案 0 :(得分:1)
请尝试这个:
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];