How to use PDFPageOverlayViewProvider?

I'm trying to use PDFPageOverlayViewProvider by copying the code provided in the "What's new in PDFKit" WWDC22 session here: https://developer.apple.com/videos/play/wwdc2022/10089/

I've copied the method implementations and set my pdfView's pageOverlayViewProvider property to the view where I implemented the protocol. However, when I try to run my app, the pdfView(_ view: PDFView, overlayViewFor page: PDFPage) method is never getting called.

Has anyone been able to get this working successfully?

It seems that PDFPageOverlayViewProvider is set in the UIViewRepresentable of PDFView derived from class Coordiantor: NSObject. I wander why Apple doesn’t provide the demo App presented in the video. Maybe, the protocol is not working yet in the beta version.

There's a recent question (asked Nov 1) posted on Stack Overflow, sharing the same problem: How to set PDFPageOverlayViewProvider for PDFView?

I'm also having difficulty getting pageOverlayViewProvider to work properly, albeit with NSViewRepresentable.

With omar_a's suggestion, I succeed in presenting overlay views for a PDF file. But the issue is I can not draw anything on canvas as WWDC's demo video. In the video, the presenter overlaid a canvas view and draw with his pencil. But I can't make the same. Should I make some custom gesture handlers PDF view to activate pencil input?

You need to also set isInMarkupMode on the PDFView instance to true, so it changes how hit testing works.

Hi ! I just figured out that setting the PDFDocument to nil in the editing PDFView Briggs the PDFPageOverlayViewProvider willEndDisplayingOverlayView(for:) delegate ! Then all custom pages get their edited content and my custom UIDocument's contents(forType:) can now grab my custom PDFPage content to burn into the .pdf file !

How to use PDFPageOverlayViewProvider?
 
 
Q