swift – in flutter, for ios app icon ought to change dynamically

Spread the love


for ios, I attempted altering app icon and its altering to default swift app icon however not the one which I wished to use.

firstly i created app icons and dumped in challenge folder, then i created methodology channel and modified appDelegate file and data.plist file as talked about under

data.plist:

<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>app_icon_b</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>app_icon_b</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
        <key>app_icon_g</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>app_icon_g</string>
            </array>
            <ke
            <false/>
        </dict>
    </dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
        <key>CFBundleIconName</key>
        <string></string>
        <key>CFBundleIconFiles</key>
        <array>
            <string>app_icon_g</string>
        </array>
        <key>UIPrerenderedIcon</key>
        <false/>
    </dict>
    <key>UINewsstandIcon</key>
    <dict>
        <key>CFBundleIconFiles</key>
        <array>
            <string></string>
        </array>
        <key>UINewsstandBindingType</key>
        <string>UINewsstandBindingTypeMagazine</string>
        <key>UINewsstandBindingEdge</key>
        <string>UINewsstandBindingEdgeLeft</string>
    </dict>
</dict>

appDelegate:

import UIKit
import Flutter
import Basis

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {

override func software(
_ software: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {

let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
    let mlkitChannel = FlutterMethodChannel(identify: "com.dynamicIcon",
                                              binaryMessenger: controller.binaryMessenger)
mlkitChannel.setMethodCallHandler({
      (name: FlutterMethodCall, consequence: @escaping FlutterResult) -> Void in
    if name.methodology == "launcherFirst"{
        if #out there(iOS 10.3, *) {
            let iconName = "app_icon_g";
            self.setIcon(iconName)
        }else {
            consequence("Not supported on iOS ver < 10.3");
               }
        /* Finish */
        }else if name.methodology == "launcherSecond"{
            /* Begin */
            if #out there(iOS 10.3, *) {
                let iconName = "app_icon_b";
                self.setIcon(iconName)
            }else {
                consequence("Not supported on iOS ver < 10.3");
                   }
            /* Finish */
            }else if name.methodology == "default"{
                    /* Begin */
                    if #out there(iOS 10.3, *) {
                        let iconName = "app_icon_g";
                        self.setIcon(iconName)
                    }else {
                        consequence("Not supported on iOS ver < 10.3");
                           }
                    /* Finish */
                    }

}
)

GeneratedPluginRegistrant.register(with: self)
return tremendous.software(software, didFinishLaunchingWithOptions: launchOptions)

}

func setIcon(_ appIcon: String) {
    print(appIcon)
        if UIApplication.shared.supportsAlternateIcons{
            UIApplication.shared.setAlternateIconName(appIcon) { error in
                if let error = error {
                    print("Error setting alternate icon (appIcon): (error.localizedDescription)")
                }
            }
            print(UIApplication.shared.alternateIconName ?? "def")
        }
    }

}

print(UIApplication.shared.alternateIconName) i get the proper app_icon identify however its not making use of within the app as a substitute default empty icon is utilized(this one: https://www.google.com/url?sa=i&url=httpspercent3Apercent2Fpercent2Fdeveloper.apple.compercent2Fdesignpercent2Fresourcespercent2F&psig=AOvVaw0IxCKxnZzg3ffMl8TNZlfS&ust=1700556656445000&supply=photographs&cd=vfe&opi=89978449&ved=0CBIQjRxqFwoTCJihv62Z0oIDFQAAAAAdAAAAABAE). please assist

Leave a Reply

Your email address will not be published. Required fields are marked *