I'd like to set my macOS app written in Swift as default app when opening .mp4 file.
I think I can do it with setDefaultApplication(at:toOpen:completion:).
https://developer.apple.com/documentation/appkit/nsworkspace/3753002-setdefaultapplication
However, permission error occurs when I use it.
The error is:
Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={NSUnderlyingError=0x6000031d0150 {Error Domain=NSOSStatusErrorDomain Code=-54 "permErr: permissions error (on file open)"}}
I tried to give my app full-disk access, but it didn't work.
I also tried to use setDefaultApplication(at:toOpenFileAt:completion:), then it works with no error, but it effects on only one file.
What I want to do is to set my app as default app of all .mp4 files.
How do I achieve this?
My code is like below:
let bundleUrl = Bundle.main.bundleURL
NSWorkspace.shared.setDefaultApplication(at: bundleUrl, toOpen: .mpeg4Movie) { error in
print(error)
}
Thank you.
Sounds like either it's not working right or the documentation needs to be updated to explain how to get it working.
Our engineering teams need to investigate this issue, as resolution may involve changes to Apple's software. Please file a bug report, include a small Xcode project and some directions that can be used to reproduce the problem, and post the Feedback number here once you do. If you post the Feedback number here I'll check the status next time I do a sweep of forums posts where I've suggested bug reports.
Bug Reporting: How and Why? has tips on creating your bug report.