UIWebView comparing current and defined URL's with a loop depending on result
I am trying to compa开发者_运维百科re the current url in webView with a defined url say google.com
so in theory..
NSURLRequest *currentRequest = [webView request];
NSURL *currentURL = [currentRequest URL];
would give us our current url...
NSString *newurl = @"http://www.google.com";
this would give us the compared to defined url
while (!currentURL == newurl) {
//do whatever here because currentURL does not equal the newurl
}
You have to use -isEqualToString:
, like so:
while (![currentURL isEqualToString:newURL]) {
// Do stuff
}
You can't use that to compare URLs to strings, tho', so you'll have to convert one or the other (converting newurl to an URL and comparing using -isEqual:
might be a good move).
精彩评论