swift – Why Does iOS Alternate Icons Not Working Correctly


I used to be making an iOS app utilizing Swift

However by some means my alternate icons not working correctly

Once I faucet the button, it says “You will have modified the icon for “App”.”, however what it modified is nothing however empty icon.

Screenshot

Console output:

+[LSApplicationProxy applicationProxyFor*] isn't a supported technique for getting the LSApplicationProxy for the present course of, use +[LSBundleProxy bundleProxyForCurrentProcess] as an alternative.

LaunchServices: retailer  or url  was nil: Error Area=NSOSStatusErrorDomain Code=-54 "course of could not map database" UserInfo={NSDebugDescription=course of could not map database, _LSLine=67, _LSFunction=_LSServer_GetServerStoreForConnectionWithCompletionHandler}

Try to map database failed: permission was denied. This try is not going to be retried.

Did not initialize shopper context with error Error Area=NSOSStatusErrorDomain Code=-54 "course of could not map database" UserInfo={NSDebugDescription=course of could not map database, _LSLine=67, _LSFunction=_LSServer_GetServerStoreForConnectionWithCompletionHandler}

Icon up to date efficiently to: white

However after I set it again to Default, it is simply work correctly

Screenshot

All icons file is in PNG format

Xcode Model: Model 15.4 (15F31d)

macOS Model: Sonoma 14.5 (23F79)

iOS system I am testing on: iPhone XR (iOS 17.6.1)

Here is the Information.plist





    CFBundleIcons
    
        CFBundleAlternateIcons
        
            Default
            
                UIPrerenderedIcon
                
                CFBundleIconFiles
                
                    AppIcon-Default
                
            
            3D
            
                UIPrerenderedIcon
                
                CFBundleIconFiles
                
                    AppIcon-3D
                
            
            White
            
                UIPrerenderedIcon
                
                CFBundleIconFiles
                
                    AppIcon-White
                
            
            Black
            
                UIPrerenderedIcon
                
                CFBundleIconFiles
                
                    AppIcon-Black
                
            
            WhiteLogo
            
                UIPrerenderedIcon
                
                CFBundleIconFiles
                
                    AppIcon-WhiteLogo
                
            
            BlackLogo
            
                UIPrerenderedIcon
                
                CFBundleIconFiles
                
                    AppIcon-BlackLogo
                
            
        
    


The swift code:

enum AppIcon: String, CaseIterable {
    case `default` = "Default"
    case threeD = "3D"
    case white = "White"
    case black = "Black"
    case whiteLogo = "WhiteLogo"
    case blackLogo = "BlackLogo"
    
    var title: String? {
        self == .default ? nil : self.rawValue
    }
    
    var description: String {
        self.rawValue
    }
    
    var icon: Picture {
        Picture("AppIcon-(self.rawValue)-Preview")
    }
}

struct IconView: View {
    @State non-public var selectedIcon: AppIcon = .default
    
    var physique: some View {
        Record {
            Part(header: Textual content("Select the app icon to interchange")) {
                ForEach(AppIcon.allCases, id: .self) { icon in
                    Button(motion: {
                        selectedIcon = icon
                        updateIcon()
                    }) {
                        HStack {
                            icon.icon
                                .resizable()
                                .aspectRatio(contentMode: .match)
                                .body(width: 50, top: 50)
                                .clipShape(RoundedRectangle(cornerRadius: 10))
                            Textual content(icon.description)
                                .font(.physique)
                            Spacer()
                            if selectedIcon == icon {
                                Picture(systemName: "checkmark.circle.fill")
                            }
                        }
                    }
                }
            }
        }
        .navigationTitle("App Icon")
        .navigationBarTitleDisplayMode(.inline)
        .onAppear {
            getCurrentIcon()
        }
    }
    
    non-public func getCurrentIcon() {
        if let iconName = UIApplication.shared.alternateIconName {
            selectedIcon = AppIcon(rawValue: iconName) ?? .default
        } else {
            selectedIcon = .default
        }
    }
    
    non-public func updateIcon() {
        print("Making an attempt to replace icon to: (selectedIcon.title ?? "default")")
        CommonUtils.updateAppIcon(with: selectedIcon.title)
    }
}

class CommonUtils {
    static func updateAppIcon(with iconName: String?) {
        DispatchQueue.foremost.async {
            UIApplication.shared.setAlternateIconName(iconName) { error in
                if let error = error {
                    print("Couldn't replace icon: (error)")
                    print("Error area: (error._domain)")
                    print("Error code: (error._code)")
                } else {
                    print("Icon up to date efficiently to: (iconName ?? "default")")
                }
            }
        }
    }
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles