0

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 の印刷を数えますが、視覚的な結果は期待したものではありません。

4

2 に答える 2

0

私は私の問題を解決しました!すべてのテストを削除し、timestamp has all level を追加しました:

NSString *html = @"<html><head></head><body>document.write(\"<a target=\"_blank\"ref=\"http://url_redirect.com?time = 123456789\"><img border=\"0\" src=\"http://url_pictures.com?time = 123456789\"></a>\");</body></html>";

NSString *baseURL = [mbAdUtil getBaseURL:html];

複数のレベル キャッシュがある場合と同じです。それは非常に奇妙ですが、うまくいきます...

私の解決策は次のとおりです。http: //url_redirect.comまたはhttp://url_pictures.comが別の URL を呼び出す場合、タイムスタンプを追加する必要があります。

于 2013-06-28T09:21:37.833 に答える
0

NSURLRequest にキャッシュ ポリシーを追加します。

NSURL *URL = [NSURL URLWithString:@"http://url_pictures.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10];
[adView loadRequest:request]; 

ソリューションに役立つ可能性が最も高い 3 つのポリシーがあります。

  • NSURLRequestReloadIgnoringLocalCacheData、
  • NSURLRequestReloadIgnoringLocalAndRemoteCacheData、
  • NSURLRequestReloadIgnoringCacheData
于 2013-06-25T22:03:01.880 に答える