How to get the link of a PDFAnnotation with characters that are not valid for the URL attribute?

Viewed 68

I set a PDFDocument with some links to a PDFView with the Apple's PDFKit library. When the user selects an item at the pdf I execute some code. I listen to this with an observer:

  observer = NotificationCenter.default.addObserver(forName: .PDFViewAnnotationHit, object: nil, queue: .main) { (not) in
        if let anot = not.userInfo!["PDFAnnotationHit"] as? PDFAnnotation {
            print(anot) }

Now, the selected PDFAnnotation has a url property that contains the pdf's link like http://iteminfo that the user pressed and then I use this link to do some stuff. The problem is that the url returns nil when the link contains characters like è or ñ or spaces. This seems to be cause the encoding of the url, but this encoding is by default. I have tried anot.widgetStringValue but it returns nil. So, How can I get this link? Thanks for your help.

0 Answers
Related