UIWebview に問題があります。WebView で写真を印刷するための URL を数回呼び出し、写真が表示された回数を数えます。
写真のURLを呼び出すと、カウントが印刷数と一致します。
NSURL *URL = [NSURL URLWithString:@"http://url_pictures.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
[adView loadRequest:request];
loadhtmlstring で URL を呼び出すと、カウンターは 1 になります。API が javascript を含む html コードを返すため、loadhtmlstring を使用することは非常に重要です。
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];
また、プロジェクトのインスタンスを破棄して別のインスタンスを作成してテストしました。私は自分のウェブビュー、すべての変数、そして覚えていないほど多くのものを破壊しました。私のカウンターは常に1です。
私のより良い解決策は次のとおりです。
[webView loadHTMLString:@"" baseURL:nil];
[webView stopLoading];
[webView setDelegate:nil];
[webView removeFromSuperview];
これで 2 から 3 の印刷を数えますが、視覚的な結果は期待したものではありません。