NSOpenPanel returning immediately in MacCatalyst

Replies

If you're able to reproduce this issue in a small sample Xcode project, I recommend you open a Technical Support Incident via the Code Level Support link on the Account page of your developer account (https://developer.apple.com/account/#CodeLevelSupportCard).

(Please note, though, that Developer Technical Support is closed over the Thanksgiving week.)

You wrote:

NSOpenPanel returning immediately in Mac Catalyst

I’m confused by this. NSOpenPanel is an AppKit API. Mac Catalyst is based on UIKit. You can’t use AppKit APIs in a Catalyst app [1]. If you want to present a file selection UI in a Catalyst app, use a UIKit API, for example, UIDocumentInteractionController.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] Well, you can, but it’s unsupported, and likely to result in weird behaviour.

Wrapping NSOpenPanel/SavePanel in a bundle that can access the more powerful macOS APIs has its uses though.

As far as I can tell there isn't a way to present UIDocumentInteractionController in the same way as NSOpenPanel -runModal. You need to present it from an existing UIViewController. Say you have an item in the menu bar that would invoke open or save and no windows are currently open (but the App is the menu bar owning app). In the Catalyst environment you can't present a freestanding UIDocumentInteractionController (unless I'm missing something?). First you need to create a window with a view controller, then present the UIDocumentInteractionController on the view controller which isn't ideal.

Also UIDocumentInteractionController doesn't have any API that bridges to NSOpenPanel/NSSavePanel UI related properties like:

@property (null_resettable, copy) NSString *prompt;



/* NSSavePanel/NSOpenPanel: Gets and sets the title for the panel shown at the top of the window.

*/

@property (null_resettable, copy) NSString *title;



/*  NSSavePanel: Gets and sets the text shown to the left of the "name field". Default value is a localized "Save As:" string.

    NSOpenPanel: Not used.

*/

@property (null_resettable, copy) NSString *nameFieldLabel; 

Etc. etc.

FWIW I'm not experiencing the OPs reported issue on Ventura 13.1.

Wrapping NSOpenPanel/NSSavePanel in a bundle that can access the more powerful macOS APIs has its uses though.

Oi vey! don’t do that.

While this is a commonly used technique, it puts you on very shaky ground compatibility-wise. In practice, the risk level varies based on how far up the software stack you are. Using this technique for low-level stuff is technically not supported but less likely to cause problems in practice. OTOH, using it for high-level stuff is very likely to cause compatibility problems in practice, if not today then in some future iteration of macOS. The open and save panels are right at the top of the software stack, where you are most likely to encounter issues.

If UIKit’s open and save panel APIs don’t meet your requirements, I recommend that you file an enhancement request for the features you need. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks for these tips.

I filed the following feedbacks related to UIDocumentInteractionController:

FB11956915

and

FB11956933

Add a Comment

Still doesn't seem possible to provide some explanation text to users for open/save panel from Mac Catalyst via UIDocumentInteractionController/UIDocumentPickerViewController unless you call into AppKit which is kind of a shame.