setAlternateIconName: did anyone manage to make it work?

I'm having issues with the icons not found:


Error Domain=NSCocoaErrorDomain Code=4 "The file doesn’t exist." UserInfo={NSUnderlyingError=0x650000055f90 {Error Domain=LSApplicationWorkspaceErrorDomain Code=-105 "iconName not found in CFBundleAlternateIcons entry" UserInfo={NSLocalizedDescription=iconName not found in CFBundleAlternateIcons entry}}}


Did anyone manage to make it work? Thanks.

Accepted Reply

Wait check this project. He managed to do it

https://github.com/steventroughtonsmith/AlternateIconTest

Replies

I have not managed to get it to work either.

I am a bit confused about how to set it up in the Info.plist. What did you do?

I've not managed to get this to work either. I've tried a number of combinations according to the documentation (https://developer.apple.com/library/prerelease/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW14)https://developer.apple.com/library/prerelease/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW14.


<key>CFBundleAlternateIcons</key>
<dict>
  <key>AlternateIcon</key>
  <dict>
       <key>CFBundleIconFiles</key>
       <array>
            <string>AltIcon</string>
       </array>
       <key>UIPrerenderedIcon</key>
       <false/>
  </dict>
</dict>


let application = UIApplication.shared
if application.supportsAlternateIcons {

    if application.alternateIconName == nil {
     
        application.setAlternateIconName("AlternateIcon") { error in
         
            print(String(describing: error))
        }
     
    } else {
        application.setAlternateIconName(nil, completionHandler: { error in
         
            print(String(describing: error))
        })
    }
}


All I get is this error which is normally a file read error:


Error Domain=NSCocoaErrorDomain Code=3072 "The operation was cancelled."


I've tried dumping the icon in the main directory of the project and referncing it simply by it's name, using the postfix @2x/@3x etc. and also tried referencing it through an assets catalog name, but nothing seems to work.


By the looks of things (https://twitter.com/stroughtonsmith/status/823988446108774400?ref_src=twsrc%5Etfw) there are additional keys that are needed for the wording to be used when telling the user that the icon is being changed, but there isn't any mention of that anywhere in the documentation that I've seen. The lack of documentation around the missing keys makes me think that maybe this feature isn't ready for release yet?


It also makes me think that this might not be as useful as I first thought e.g you wont be able to simulate what the calendar app is doing by changing the icon every daty to reflect the date, or changing to reflect the current weather. It looks like it might just be for seasonal changes (you see many apps in the app store making updates just to change to a christmas theme for example) or maybe for upgrading from a free version to a paid version. I can see why it's not a free for all at changing out the icons as the home screen could turn into a disco of alternating icons, but maybe this could be fixed with review guidelines?

I followed the documentation and added a CFBundleAlternateIcons as a subentry of CFBundleIcons (sibling of CFBundlePrimaryIcon) and I tried either adding the same structure as CFBundlePrimaryIcon or making it an array. Nothing worked in both cases.

I also tried both using xcassets and files.

Same as this. Glad it's not just myself! Also as a side note, the popup you get when setting to the primary icon (by passing nil) is ugly af.

It's scary! Does it means this will only be possible when the app is in foreground? Will it happen every single time? I've also seen a tweet showing a permission dialog. Would that be shown every time the icon is changed?

As another note; setting 'nil' on both the name and completionHandler causes a crash even though the completion handler is nullable and is set to nil by default.


UIApplication.shared.setAlternateIconName(nil, completionHandler: nil)


Another thing that makes me think that this API isn't quite ready to be released to us thugs 😉

Still nice to see that the feature will be ready and start thinking about how to use it ;-)

jotwee did you manage to make it work? I followed that documentation but it was not working and then I posted the question.

Could you share your plist and code?

Followed the same specifications and got the same error as micheleaiello


Here is my part of info.plist

<dict>
     <key>CFBundleAlternateIcons</key>
     <dict>
          <key>CFBundleIconFiles</key>
          <array>
               <string>Icon29@3x</string>
          </array>
     </dict>
     <key>CFBundlePrimaryIcon</key>
     <dict>
          <key>CFBundleIconFiles</key>
          <array>
               <string>Icon29@3x</string>
          </array>
     </dict>
</dict>


I used the same file to be sure it works. The primary icon correctly sets the app icon. But used as an alternate icon it doesn't work at all.

Wait check this project. He managed to do it

https://github.com/steventroughtonsmith/AlternateIconTest

Someone shared a working app on github: https://github.com/steventroughtonsmith/AlternateIconTest

Steven Troughton Smith was kind enough to upload his working example to github. See this:

https://github.com/steventroughtonsmith/AlternateIconTest


This example works for me.

There is sample app on Github is working with alternate icons (named AlternateIconTest).


Posting a link to it causes my post to be moderated, so you will just need to search for it.

Has anyone seen improvements with beta 2?

Like Assets support…


I don't see assets not being supported because app icon size varies on the device (iPad/iPhone), this would lead to add more than 3 files for each icon.