You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取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 UIApplicationSupportsAlternateIcons key in your Info.plist and set its value to YES — 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 CFBundleIcons structure:
    • You need a CFBundlePrimaryIcon entry (even if it just points to your default icon files) so the system knows what the "original" icon is.
    • Each entry under CFBundleAlternateIcons must have a valid CFBundleIconName and CFBundleIconFiles array pointing to your icon assets.

使用官方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 CFBundleIconName in your Info.plist — even a single uppercase/lowercase mismatch will cause the API to return nil.
  • 缓存问题: 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:02:29