allowedFileTypes is deprecated

Viewed 801

In macOS 11.0, the NSOpenPanel's allowedFileTypes property is marked as deprecated in favor of the allowedContentType property.

We're developing a plug-in to a third-party macOS app. The plug-in asks user to provide a licence file - we provide the file with our proprietary abcLicence file extension. As we cannot handle double clicks as a plug-in, we rely on NSOpenPanel triggered from the plug-in UI. Because there were close to no benefit registering the file type as we cannot respond on shell file actions, we are not including it in the plug-ins plist file. The plug-in supports macOS 10.12+.

NSOpenPanel *openDialog = [NSOpenPanel openPanel];
openDialog.title = @"Locate ABC license file";
openDialog.allowedFileTypes = @[@"abcLicence"];

How to update the code to use the new API if available while keeping supporting macOS 10.12+?

1 Answers

Use the delegate method panel:shouldEnableURL:, available since 10.6. With this method you can implement arbitrary logic to decide if an item should be enabled and hence selectable, in your case you can just check the extension. HTH

Related