Can I change app icon programmatically

后端 未结 8 2144
执笔经年
执笔经年 2020-11-30 11:44

I have two app icons built-in (free and premium), is it possible to replace free icon to premium icon programmatically after in-app purchase is completed successfully?

8条回答
  •  情书的邮戳
    2020-11-30 12:21

    There is a new solution for this situation.

    You can use

    setAlternateIconName(_:completionHandler:)
    

    iOS 10.3 is out with xcode 8.3.

    10.3+

    Update:

    Usage is pretty simple, the key is to find out plist usage and note that you can not load assets from xcassets ( at least didnt work for me ). You need to add your icon files to project and prefer 180x180 images for quality.

    You need to use "Icon files (iOS 5)", new Icon files does not work.

    One last thing, when you change icon on a button click it will popup a Alert window that says 'You have changed the icon for "IcoTest".'

    //ViewController.swift
    @IBAction func ico1Click(_ sender: Any) {
        if UIApplication.shared.supportsAlternateIcons{
            UIApplication.shared.setAlternateIconName("Icon2", completionHandler: { (error) in
                print(error ?? "")
            })
        }else{
            print("NO NO")
        }
    }
    
    //Info.plist
    CFBundleIcons
    
        CFBundleAlternateIcons
        
            Icon1
            
                CFBundleIconFiles
                
                    alternater1_180x180
                
                UIPrerenderedIcon
                
            
            Icon2
            
                CFBundleIconFiles
                
                    alternater2_180x180
                
            
        
    
    

提交回复
热议问题