Skip to content

Commit fa46aba

Browse files
committed
fix: Fix an issue with retrieving the app icon on iOS.
1 parent 7f2a1db commit fa46aba

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// UIApplication.swift
3+
// StoreKitHelper
4+
//
5+
// Created by wong on 12/31/25.
6+
//
7+
8+
#if canImport(UIKit)
9+
import UIKit
10+
11+
extension UIApplication {
12+
static func applicationIconImage() -> UIImage? {
13+
guard
14+
let icons = Bundle.main.infoDictionary?["CFBundleIcons"] as? [String: Any],
15+
let primary = icons["CFBundlePrimaryIcon"] as? [String: Any],
16+
let iconFiles = primary["CFBundleIconFiles"] as? [String],
17+
let iconName = iconFiles.last
18+
else {
19+
return nil
20+
}
21+
return UIImage(named: iconName)
22+
}
23+
}
24+
#endif

Sources/StoreKitHelper/Views/StoreKitHelperSelectionView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ private struct HeaderView: View {
194194
Image(nsImage: NSImage(named: NSImage.applicationIconName)!)
195195
.resizable()
196196
.frame(width: 28, height: 28)
197-
#else
198-
if let appIcon = Bundle.main.icon {
197+
#endif
198+
#if canImport(UIKit)
199+
if let appIcon = UIApplication.applicationIconImage() {
199200
Image(uiImage: appIcon)
200201
.resizable()
201202
.scaledToFit() // 适应图标的比例

Sources/StoreKitHelper/Views/StoreKitHelperView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ private struct HeaderView: View {
201201
Image(nsImage: NSImage(named: NSImage.applicationIconName)!)
202202
.resizable()
203203
.frame(width: 76, height: 76)
204-
#else
205-
if let appIcon = Bundle.main.icon {
204+
#endif
205+
#if canImport(UIKit)
206+
if let appIcon = UIApplication.applicationIconImage() {
206207
Image(uiImage: appIcon)
207208
.resizable()
208209
.scaledToFit() // 适应图标的比例

0 commit comments

Comments
 (0)