setAlternateIconName with nothing changed

the finish block for setAlternateIconName and the alert show me that it changes the icon sccessfully,but when I turn the app to background i see that the icon is the original one.. so who can tell me where is wrong?
Answered by Mingyu-Liu in 667962022

Hi 黑子 刘,
Thank you for the sample project. Your alternate icons aren’t working because of several issues in the Info.plist file:

<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>changeicon</key>
<dict>
<key>Icon files</key>
<array>
<string>changeicon</string>
</array>
</dict>
</dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string></string>
</array>
<key>CFBundleIconName</key>
<string></string>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>UINewsstandIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string></string>
</array>
<key>UINewsstandBindingEdge</key>
<string>UINewsstandBindingEdgeLeft</string>
<key>UINewsstandBindingType</key>
<string>UINewsstandBindingTypeMagazine</string>
</dict>
</dict>
  1. For CFBundlePrimaryIcon, you aren’t declaring an icon name. Since your main app icon is defined by the asset catalog, you should remove CFBundlePrimaryIcon from the Info.plist file.

  2. Under CFBundleAlternateIcons, you have the key name Icon files. This should be CFBundleIconFiles.

  3. UINewsstandIcon is no longer used. Newsstand was an iOS feature that was removed in iOS 9. You should also remove this from the Info.plist file.

On top of these Info.plist issues, you should provide icons that are correctly sized for every device. The details of these sizes for alternate app icons are documented in the User-Selectable App Icons section of the Human Interface Guidelines:
<https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/app-icon/>
I assume you speak of completion handler.

Could you show the code for:
  • setAlternateIconName(…) call

  • the alert

Did you test for errorCode ?

the alert show me that it changes the icon successfully

Which alert are you speaking about ?

Doc says there is no need to dispatch to main queue:

completionHandler
A handler to be executed with the results. After attempting to change your app's icon, the system reports the results by calling your handler. (The handler is executed on a UIKit-provided queue, and not necessarily on your app's main queue.) The handler has no return value and takes the following parameter:

Check also the notice:

Discussion
Use this method to change your app's icon to its primary icon or to one of its alternate icons. You can change the icon only if the value of the supportsAlternateIcons property is true.
You must declare your app's primary and alternate icons using the CFBundleIcons key of your app's Info.plist file. For information about how to configure alternate icons for your app, see the description of the CFBundleIcons key in Information Property List Key Reference.




  • (IBAction)gonext:(id)sender {

if ([[UIApplication sharedApplication] supportsAlternateIcons]) {
NSString *name = [UIApplication sharedApplication].alternateIconName;
if (name&&[name isEqualToString:@"changeicon"]) {
[[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:^(NSError * _Nullable error) {
Code Block
}];
}else{
[[UIApplication sharedApplication] setAlternateIconName:@"changeicon" completionHandler:^(NSError * _Nullable error) {
}];
}
}
}
Your code was not completely formatted.

In which func is this part of code called ?

Code Block
if ([[UIApplication sharedApplication] supportsAlternateIcons]) {
NSString *name = [UIApplication sharedApplication].alternateIconName;
if (name&&[name isEqualToString:@"changeicon"]) {
[[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:^(NSError * _Nullable error) {
}];
} else {
[[UIApplication sharedApplication] setAlternateIconName:@"changeicon" completionHandler:^(NSError * _Nullable error) {
}];
}
}
}


Could you log the error lines 5 and 9 ? and add a NSLog to check which branch of the if / else is used.

Line 4, if name isEqualToString:@"changeicon" (which should always be true), then you return to app's primary icon.
Is it intentional ? AFAIU, you should systematically execute line 4 and never 8.
Accepted Answer

Hi 黑子 刘,
Thank you for the sample project. Your alternate icons aren’t working because of several issues in the Info.plist file:

<key>CFBundleIcons</key>
<dict>
<key>CFBundleAlternateIcons</key>
<dict>
<key>changeicon</key>
<dict>
<key>Icon files</key>
<array>
<string>changeicon</string>
</array>
</dict>
</dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string></string>
</array>
<key>CFBundleIconName</key>
<string></string>
<key>UIPrerenderedIcon</key>
<false/>
</dict>
<key>UINewsstandIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string></string>
</array>
<key>UINewsstandBindingEdge</key>
<string>UINewsstandBindingEdgeLeft</string>
<key>UINewsstandBindingType</key>
<string>UINewsstandBindingTypeMagazine</string>
</dict>
</dict>
  1. For CFBundlePrimaryIcon, you aren’t declaring an icon name. Since your main app icon is defined by the asset catalog, you should remove CFBundlePrimaryIcon from the Info.plist file.

  2. Under CFBundleAlternateIcons, you have the key name Icon files. This should be CFBundleIconFiles.

  3. UINewsstandIcon is no longer used. Newsstand was an iOS feature that was removed in iOS 9. You should also remove this from the Info.plist file.

On top of these Info.plist issues, you should provide icons that are correctly sized for every device. The details of these sizes for alternate app icons are documented in the User-Selectable App Icons section of the Human Interface Guidelines:
<https://developer.apple.com/design/human-interface-guidelines/ios/icons-and-images/app-icon/>
setAlternateIconName with nothing changed
 
 
Q