setAlternateIconName(_:completionHandler:)
Changes the icon the system displays for the app.
Declaration
func setAlternateIconName(_ alternateIconName: String?, completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)func setAlternateIconName(_ alternateIconName: String?) async throwsParameters
- alternateIconName:
The name of the alternate icon, as declared in the
CFBundleAlternateIconskey of your app’sInfo.plistfile. Specifynilif you want to display the app’s primary icon, which you declare using theCFBundlePrimaryIconkey. Both keys are subentries of theCFBundleIconskey in your app’sInfo.plistfile. - completionHandler:
The handler to execute with the results. After attempting to change your app’s icon, the system reports the results by calling your handler. The handler executes 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:
- error
On success, the value of this parameter is
nil. If an error occurred, this parameter contains the error object indicating what happened and the value of the Alternateiconname property remains unchanged.
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 configure your app’s primary icon asset in the “App Icons and Launch Images” section of the General pane or set it directly using the “Primary App Icon Set Name” build setting. You specify the names of additional icon assets available to your app using the “Alternate App Icon Sets” build setting. Xcode uses these setting to generate the entries for CFBundlePrimaryIcon and CFBundleAlternateIcons under the top-level key CFBundleIcons. For more information, see Build settings reference and Configuring your app icon using an asset catalog.