문제

I'm trying my best to optimize the time it takes to load a webpage in my uiwebview. How can I track the number of milliseconds it takes to load it? This is more for me to see if my optimizations are working.

UPDATE: I've been using delegate methods, but the problem isn't knowing when it's finished loading, or when it began loading. I want to know how long it took from when it first began the request to when it finished loading the url (the actual time in milliseconds).

도움이 되었습니까?

해결책

Set a property called NSDate *methodStart.

When you start loading webView:

methodStart = [NSDate date];

When finished do that:

NSDate *methodFinish = [NSDate date];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:methodStart];
NSLog(@"executionTime = %f", executionTime);

Take into account that a webView usually calls webViewDidFinishLoad: a few times so you will get the NSLog a few times and the last one is the one you need.

다른 팁

Log from the start of the request (also set the delegate for the UIWebView)

webView loadRequest

OR

webView loadHTMLString: baseURL:

OR

webView loadData: MIMEType: textEncodingName:   

Depending which one you are using

And log once its done via the UIWebViewDelegate method

- (void) webViewDidFinishLoad: (UIWebView*) webView
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top