Dynamic Icon Change for iphone

前端 未结 3 2042
星月不相逢
星月不相逢 2021-01-01 03:34

My question is also same that others asked before.

I found that once you set the Icon for the Application we can\'t change the Application

3条回答
  •  一向
    一向 (楼主)
    2021-01-01 04:08

    iOS 10.3+

    There is a method called setAlternateIconName: which is introduced in iOS 10.3, through which you can change the app's icon, however these icons should be predefined. It means that the icons should be added to the app's bundle and referenced in the info.plist.

    Example:

    A typical info.plist looks like:

    CFBundleIcons
    
        CFBundleAlternateIcons
        
            alternate_icon_name
            
                CFBundleIconFiles
                
                    alternate_icon_file
                
                UIPrerenderedIcon
                
            
            CFBundlePrimaryIcon
            
                CFBundleIconFiles
                
                    default_icon_file
                
                UIPrerenderedIcon
                
            
        
    
    

    Implement the code like:

    Objective C:

    [[UIApplication sharedApplication] setAlternateIconName:@"alternate_icon_name" completionHandler:^(NSError * _Nullable error) {
        NSLog(@"Error...");
    }];
    

    Swift 3:

    if UIApplication.shared.supportsAlternateIcons
    {
        UIApplication.shared.setAlternateIconName("alternate_icon_name", completionHandler: { (error) in
            print(error ?? "")
        })
    }
    

    Before iOS 10.3

    You cannot change the icon file dynamically, because the icon file name is stored on the application plist.

    Application plist.

    You cannot change the application plist dynamically, because it is stored on the application bundle which is readonly.

    So your requirement is not possible.

提交回复
热议问题