How can I access native osx NSWorkspace object from MAUI to execute openfile?

Yiannis B 21 Reputation points
2022-12-03T13:58:08.15+00:00

I am trying to open a file (pdf) using the default OSX application. Based on the Apple docs I can use the openFile command like this:

NSWorkspace.shared.openFile("/Myfiles/README", withApplication: "TextEdit")

docs: https://developer.apple.com/documentation/appkit/nsworkspace

How can I access the NSWorkspace object from my MAUI platform specific code? I tried to include AppKit but it is not there.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,487 questions
0 comments No comments
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 31,166 Reputation points Microsoft Vendor
    2022-12-05T09:28:45.63+00:00

    Hello @Yiannis B ,
    The underlying platform about Mac that supports MAUI uses Mac Catalyst, NSWorkspace is not available for MacCatalyst, it's available on macOS 10.0+.

    I am trying to open a file (pdf) using the default OSX application

    You could try using Launcher to open another app via a file. Or try to use UIDocumentInteractionController, or try to use PDFView(PDFView cannot open another app).
    In addition, MacCatalyst apps are granted access to a part of AppKit in the SDK by Apple. If you need the full Mac Platform API Support with MAUI/MacCatalyst, you can create a feature request at https://github.com/dotnet/maui .

    ---Update---
    This is a Catalyst limitation. Catalyst is essentially the iOS API running on a Mac and has limited functionality by Apple's design. It uses iOS's UIKit rather than MacOS's AppKit. So, you can use UIApplication.SharedApplication.OpenUrlAsync instead of NSWorkspace.shared.openFile, and it will open the share options menu.

    Best Regards,
    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.