PDFKit: Unable to add custom menu items to edit menu.

iPad OS, Beta 5


Adding custom menu items to UIMenuController.shared.menuItems does not work in PDFKit on Beta 5. It does work in UITextView. It used to work in previous OS releases.


1. Add menu item(s) to UIMenuController.shared.menuItems

2. Select Text


Result: Built-in edit menu items appear, but any items added programmatically do not.

Expected Result: Both built in and items added programattically appear.


SAMPLE Code to demonstrate follows:


extension Selector {
    static let customAction = #selector(ViewController.customAction(menuItem :))
}

class ViewController: UIViewController {

    @objc func customAction(menuItem : UIMenuItem) {
        print("Custom Action")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.

        let customItem = UIMenuItem(title: "My MenuItem", action: .customAction)

        UIMenuController.shared.menuItems = [customItem]
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        let path = Bundle.main.path(forResource: "Psych", ofType: "pdf")

        let pdfView = PDFView(frame: view.bounds)
        view.addSubview(pdfView)
        pdfView.document = PDFDocument(url: URL(fileURLWithPath: path!))
    }

    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        let canShow = action == .customAction

        print(action.description + " \(canShow)")

        return canShow
    }
}
Post not yet marked as solved Up vote post of KennethFra Down vote post of KennethFra
2.8k views

Replies

This is a cricial feature for my app. Without the custom menu items coming up, the main purpose of my app has been made unusable. Is there any suggestions from anyone how I might move forward with getting some response or attention in this?

The same problem as mine. It seems like Apple updates the text selection logic for PDFKit in iOS 13. Anyone can help us fix this?

This bug continues to exist in Beta 7.

I thought I was just going crazy. I have the same issue. I believe the first 13.1 beta has the same issue.

Filed this: FB7165503

Thanks!

Hey all, this is fixed in iPadOS 13.1 beta 2

Not tried on other os updates though.

I recompiled with GM Xcode 11 and i still have the issue the FIRST time on iPadOS 13.1b3. After that, menus show ok.

iOS 13.0 GM seed does not show the menus. We'll have to hope users upgrade through 13.0 quickly!

I am having reports from some users that they see my custom menuItem and some dont. I myself have it on one of my test devices XsMax and not on another iPhone 8.

Hello all, how can I disable UIMenueItem in the PDFView in iOS 13?