I have a URL rendered as a NSString in my iOS app. Right now if the user taps the URL, it will open the webpage in Safari. Is there a way to catch the tap and open it in a UIWebView? I have the UIWebView controller all setup, just need to catch the URL click. Thanks!
Here’s the code that renders the URL right now.
[detailInfoList addObject: [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInteger:kCarrierInfo], @"type",
[NSString stringWithFormat:@"http://www.ups.com/track/%@/%@", userPackage.carrier, userPackage.trackingNumber],
@"link", nil]];
Edit: Your URL won’t be caught and passed to UIWebView automatically. You have to put some procedures / methods in place to catch it. Otherwise, it will be handed over to Safari, e.g. links in UITextView.
You have to pass the URL to the instance of UIWebView. Whether you have sub-classed it as a new ViewController or it is an object within your current viewController, you can set its URL by calling
loadRequestmethod:You can alternatively, use
requestWithURL:(NSURL *)theURL cachePolicy:(NSURLRequestCachePolicy)cachePolicy timeoutInterval:(NSTimeInterval), which I personally prefer, because you can customize it with more options.Here are useful links to read:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSURLRequest_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSURLRequest
http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/doc/c_ref/NSURL