Trigger In-App-Browser after tapping on Annotation with PDFKit - iOS 11

谁都会走 提交于 2019-12-24 09:33:32

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!