I have a very simple UIWebView with content from my application bundle. I would like any links in the web view to open in Safari instead of in the web view. Is this possible?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
If anyone wonders, Drawnonward's solution would look like this in Swift:
Add this to the UIWebView delegate:
(edited to check for navigation type. you could also pass through
file://
requests which would be relative links)Swift Version:
Swift 3 version:
Update
As
openURL
has been deprecated in iOS 10:Here's the Xamarin iOS equivalent of drawnonward's answer.
In my case I want to make sure that absolutely everything in the web view opens Safari except the initial load and so I use...
In Swift you can use the following code:
Make sure you check for the URL value and the navigationType.
One quick comment to user306253's answer: caution with this, when you try to load something in the UIWebView yourself (i.e. even from the code), this method will prevent it to happened.
What you can do to prevent this (thanks Wade) is:
You might also want to handle the
UIWebViewNavigationTypeFormSubmitted
andUIWebViewNavigationTypeFormResubmitted
types.