如何获取iOS当前使用的备选应用图标名称?
解决iOS获取当前应用图标信息的问题
Hey there! I’ve dealt with this exact problem before, so let me share what worked for me.
先确认你的Info.plist配置是否完整
There are two easy-to-miss settings that break this functionality:
- Make sure you’ve added the
UIApplicationSupportsAlternateIconskey in your Info.plist and set its value toYES— this is the master switch for enabling alternate icons, and without it, the system won’t recognize your alternate icon setup at all. - Double-check your
CFBundleIconsstructure:- You need a
CFBundlePrimaryIconentry (even if it just points to your default icon files) so the system knows what the "original" icon is. - Each entry under
CFBundleAlternateIconsmust have a validCFBundleIconNameandCFBundleIconFilesarray pointing to your icon assets.
- You need a
使用官方API获取当前图标
Forget those old workaround methods — Apple added a native, reliable property for this in iOS 10.0+, which is safe to use in production:
Swift 代码示例:
import UIKit func getCurrentAppIconName() -> String? { return UIApplication.shared.alternateIconName } // 使用方式 if let iconName = getCurrentAppIconName() { print("当前使用的是备选图标:\(iconName)") } else { print("当前使用的是默认图标") }
Objective-C 代码示例:
#import <UIKit/UIKit.h> NSString *getCurrentAppIconName() { return [UIApplication sharedApplication].alternateIconName; } // 使用方式 NSString *currentIcon = getCurrentAppIconName(); if (currentIcon) { NSLog(@"当前使用的是备选图标:%@", currentIcon); } else { NSLog(@"当前使用的是默认图标"); }
常见排查点
- 大小写敏感: The icon name you use in code must exactly match the
CFBundleIconNamein your Info.plist — even a single uppercase/lowercase mismatch will cause the API to returnnil. - 缓存问题: If you’ve just updated your Info.plist, try deleting the app from your device/simulator, cleaning your Xcode build folder (Cmd+Shift+K), and rebuilding from scratch.
- iOS版本: This API works on iOS 10.0 and later. If you need to support way older versions, you’ll have to use a different approach, but realistically, most users are on iOS 13+ now.
Give these steps a shot, and you should be able to get the current icon name without any trouble!
内容的提问来源于stack exchange,提问作者jQ Goo
相关产品推荐
相关产品推荐

