Random player
Random player

Reputation: 232

How to set alternative icon in Mac Catalyst app?

On iOS, we can easily use: "try await UIApplication.shared.setAlternateIconName("iconName")" to set an alternate icon.

When running the app for MacCatalyst, that method is not working, throwing the following error:

Error Domain=NSCocoaErrorDomain Code=3328 "The requested operation couldn’t be completed because the feature is not supported."

I came across this post, from which I understand I can use NSApp to set the icon.

  let nsApp = Dynamic.NSApplication.sharedApplication
  let newIcon = UIImage(named: "iconName"!)
  nsApp.applicationIconImage = newIcon

That code works, but only temporarily (until the app is closed).

Can anybody please help? I have seen apps like Arc browser offering this functionality on the mac.

Thank you

Upvotes: 0

Views: 44

Answers (1)

Random player
Random player

Reputation: 232

Thank you @Marek-h for your suggestion. Using NSWorkspace.shared.setIcon(image, forFile: bundle.path, options: []) has the same effect, only works temporarily while the app is opened.

Seems like the reason the icon keeps reverting back is because I'm running a signed app. MacOS's code signing and app sandboxing prevent permanent modifications to the app bundle, which is what I'm trying to do when setting the icon.

Seems like the only way to do this for now will be to distribute the app from outside the App Store.

Upvotes: 0

Related Questions