问题
I´m working on an app with Apple's PDFKit and have managed to put some Annotation-Buttons with a working PDFActionURL
, which open the iOS standard browser after tapping on them.
Unfortunately, I did not find a working solution, how to open the associated links in an In-App-Browser or to load it in a webview. After tapping the AnnotationButton PDFKit automatically opens Safari and I haven´t found a property or another way concerning iOS to influence this behavior by manipulating f.e. the PDFAction.
let urlString = "https://www.apple.com"
let urlAction = PDFActionURL(url: urlString)
urlButton.action = urlAction
pdfPage.addAnnotation(urlButton)
Is there a way to force the call of an In-App-Browser at every UIApplication.shared.open()
or to manipulate the execution of a PDFAction
?
回答1:
Finally, I figured it out for myself ;) I´ve overlooked one function of the PDFViewDelegate
By setting the delegate of the pdfView to the involved ViewController and using this function
func pdfViewWillClick(onLink sender: PDFView, with url: URL) {
print(url)
}
you are able to use the associated URL of the PDFActionButton and to trigger an In-App-Browser (e.g. SFViewController).
回答2:
You want to instantiate the view like so:
let webV:UIWebView = UIWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height))
webV.loadRequest(NSURLRequest(URL: NSURL(string: "http://www.google.co.in")))
webV.delegate = self;
self.view.addSubview(webV)
Found HERE
To do it right, I would create a new ViewController
in your storyboard, nested in a navigationController
and segue to the view on annotation selection. Display your content on viewDidLoad
using a similar set of code as seen above. That code is probably in an older version of swift so you'll need to update it. There is more detail about using the delegate
associated in the link provided.
来源:https://stackoverflow.com/questions/49034120/trigger-in-app-browser-after-tapping-on-annotation-with-pdfkit-ios-11