4

I have seen this application on iTunes, it is creating custom icon in iphone. In my application I also want to change icon , specifically what I want to do is in my icon there is one label and programmatically I want to change the value of label.

Krunal
  • 68,602
  • 40
  • 230
  • 241
S S
  • 614
  • 1
  • 6
  • 16
  • this is not feasible. – Saurabh Passolia Feb 10 '14 at 05:51
  • @samfisher check out my answer. They are just basically tricking user into thinking they tapped an app icon whereas they really are just clicking on a web view home screen shortcut. – Enrico Susatyo Feb 10 '14 at 05:53
  • 1
    yes I know, the app referenced above just played trick. My comment refers regarding the actual technical implementation through Objective-C code. – Saurabh Passolia Feb 10 '14 at 05:57
  • Possible duplicate of [Can I change app icon programmatically](http://stackoverflow.com/questions/10042275/can-i-change-app-icon-programmatically) – ymutlu Jan 25 '17 at 12:32

4 Answers4

1

From the video tutorial of the app, it seems like all they're doing is they created a web page with favicon of the custom icon that you created, then the user would tap "Add To Home Screen" to add the custom web page to the home screen. That should be enough to get you going.

Enrico Susatyo
  • 18,061
  • 17
  • 89
  • 153
  • How can I change label on appicon in my application ? – S S Feb 10 '14 at 05:55
  • icon is of white color and there is one text on icon for displaying some value, I want to change that text programmatically – S S Feb 10 '14 at 06:43
1

It is possible to change appIcon from iOS 10.3.

Swift 3:

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

Objective C:

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

set supportsAlternateIcon to Yes in info.plist. Both primary and secondary icons should be added in CFBundleIcons key of your app's Info.plist file.

//Info.plist
<key>CFBundleIcons</key>
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>Icon1</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>icon1</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
        <key>Icon2</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>icon2</string>
            </array>
        </dict>
    </dict>
</dict>

References:

Krunal
  • 68,602
  • 40
  • 230
  • 241
0

This is not possible. Unless your app is of Newsstand category. For newsstand app, change the icon using the code,

UIApplication *app = [UIApplication sharedApplication];
[app setNewsstandIconImage:newsstandImage];

Note: What @Enrico suggests is a different solution. Your app icon will still be there in home screen, a duplicate icon will be created. Which most of the users wont prefer.

KingofBliss
  • 14,909
  • 6
  • 47
  • 71
0

Only my two cents.

Adding to plist directly is fine, the net effect is to have a "strange" value (IOS5...) in plist if seen visually in Xcode:

enter image description here

2) on simulator (Xcode 10 beta...) debug console on run you will see:

MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.

but works

3) don't call directly in AppDelegate. if needed so, call it dispatched:

    final func changeIcon(){

        let name = "Icon1"
        let icon = UIImage(named:  name)
        if UIApplication.shared.supportsAlternateIcons{
            UIApplication.shared.setAlternateIconName(name, completionHandler: { (error) in

                print(error ?? "ok")
            })
        }
    }

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        let when = DispatchTime.now() + 1
        DispatchQueue.main.asyncAfter(deadline: when) {
            self.changeIcon()
        }

        return true
    }
.....

4) note: icon name is the symbolic name you put in key in upper level, so for example:

<key>CFBundleIcons</key>
<dict>
    <key>CFBundleAlternateIcons</key>
    <dict>
        <key>Icon1</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>logo2_120x120</string>
            </array>
            <key>UIPrerenderedIcon</key>
            <false/>
        </dict>
        <key>Icon2</key>
        <dict>
            <key>CFBundleIconFiles</key>
            <array>
                <string>logo3_120x120</string>
            </array>
        </dict>
    </dict>
</dict>

and do NOT add @2x or similar in plist.

ingconti
  • 9,213
  • 2
  • 51
  • 39