0

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

1
  • Have you tried NSWorkspace.shared.setIcon(image, forFile: bundle.path, options: []) ? Commented Feb 14 at 6:58

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.