最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - How to set alternative icon in Mac Catalyst app? - Stack Overflow

programmeradmin4浏览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

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

Share Improve this question asked Feb 14 at 4:49 Random playerRandom player 2321 gold badge6 silver badges16 bronze badges 1
  • Have you tried NSWorkspace.shared.setIcon(image, forFile: bundle.path, options: []) ? – Marek H Commented Feb 14 at 6:58
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论