UIDocumentInteractionController not available in Mac catalyst

455 Views Asked by At

May app getting crash when execute below code.

Code: self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:targetURL];

Crash log: Terminating app due to uncaught exception 'NSGenericException', reason: 'UIDocumentInteractionController not available'

is there any solution for this issue or any alternative class?

2

There are 2 best solutions below

3
Adam On

It’s not available in Catalyst, despite what the docs say.

You could explore using an AppKit alternative (QLPreviewPanel), but you’ll have to do some hacking to get it to work from a Catalyst app: https://stackoverflow.com/a/32814132/1601849

0
Sergio Strati On

If you want to leave compatibility with OSX 10.5, you can do this check:

if UIDevice.current.systemName == "Mac OS X" {
   let version = Int (UIDevice.current.systemVersion.prefix (2)) ?? 10
   if version > 10 {
      self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:targetURL];
   } else {
      //do something
   }
} else {
   self.documentInteractionController =[UIDocumentInteractionController interactionControllerWithURL:targetURL];


}