【发布时间】:2013-06-22 12:36:38
【问题描述】:
我遇到了 UIWebview 的问题。我在我的 web 视图中调用了几次打印图片的 url,我计算了我的图片显示了多少次。
当我调用图片的url时,计数与打印数量匹配。
NSURL *URL = [NSURL URLWithString:@"http://url_pictures.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
[adView loadRequest:request];
当我用 loadhtmlstring 调用 url 时,我的计数器为 1。使用 loadhtmlstring 对我来说非常重要,因为我的 API 会返回一个带有 javascript 的 html 代码。
NSString *html = @"<html><head></head><body>document.write(\"<a target=\"_blank\"ref=\"http://url_redirect.com\"><img border=\"0\" src=\"http://url_pictures.com\"></a>\");</body></html>";
NSString *baseURL = [mbAdUtil getBaseURL:html];
NSString *script = [[NSString alloc] initWithFormat:@"%@", html];
[adView loadHTMLString:script baseURL:[NSURL URLWithString:baseURL]];
我测试了很多我的计数器与打印相同的东西。
这是我测试的一些例子:
[webView loadHTMLString:@"" baseURL:nil];
[webView stopLoading];
[webView setDelegate:nil];
[webView removeFromSuperview];
另一个:
// remove all cached responses
[[NSURLCache sharedURLCache] removeAllCachedResponses];
// set an empty cache
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
// remove the cache for a particular request
[[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];
另外,我通过销毁我的项目实例并创建另一个来进行测试。 我破坏了我的 webview,我所有的变量......还有很多我不记得的东西。 我的计数器总是 1。
我更好的解决方案是:
[webView loadHTMLString:@"" baseURL:nil];
[webView stopLoading];
[webView setDelegate:nil];
[webView removeFromSuperview];
有了这个,我计算了 2 到 3 次打印,但视觉结果不是我所期望的。
【问题讨论】:
-
你的计数变量是如何实现的?
-
当我调用url时我的计数变量在数据库中,数据库是递增的
标签: html ios caching uiwebview request