I have an Xcode 14.1 project that has a target with two destinations: "iPad" and "Mac (Designed for iPad)".
The code shown in this question is simplified from the actual project to illustrate the problem.
Since SwiftUI does not directly support PDFView directly the app has a PDFView wrapped in UIViewRepresentable:
import PDFKit
import SwiftUI
struct MyPDFView: UIViewRepresentable {
func makeUIView(context: Context) -> UIView {
let path = Bundle.main.path(forResource: "basic-link-1", ofType: "pdf")!
let pdfDocument = PDFDocument(url: URL(filePath: path))
let pdfView = PDFView()
pdfView.document = pdfDocument
pdfView.autoScales = true
return pdfView
}
func updateUIView(_ uiView: UIView, context: Context) {
}
}
("basic-link-1.pdf" is a simple PDF file that I got from an Adobe tutorial. It is a one-page document with various Link annotations.)
The PDFView is shown in the app's main view:
import SwiftUI
struct ContentView: View {
var body: some View {
MyPDFView()
}
}
When I run the app on an iPad or iPad simulator, the Link annotations in "basic-link-1.pdf" work. Tapping on one of them takes the user to another page in the document or opens a web page (depending on the exact type of link in the Link annotation).
When I run the same app directly on Mac in "Mac (Designed for iPad)" mode, nothing happens when I click on the links in the PDF view. Does anyone know what is different about this mode or what I have to do differently to get the links to react to clicks?
Additional info: I don't show it in my sample code here, but if I register a PDFViewDelegate for MyPDFView, its pdfViewWillClick(onLink:sender:url) callback gets called if the app is running on an iPad, but does not get called if the app is running in "Mac (Designed for iPad)" mode.
Also, all development and testing above was done on a MacBook Air M2.