GithubHelp home page GithubHelp logo

tastelessjolt / flutter_dynamic_icon Goto Github PK

View Code? Open in Web Editor NEW
93.0 4.0 43.0 5.99 MB

A flutter plugin for dynamically changing app icon and app icon batch number

License: BSD 3-Clause "New" or "Revised" License

Java 9.86% Ruby 7.71% Objective-C 30.57% Dart 51.86%

flutter_dynamic_icon's Introduction

flutter_dynamic_icon

A flutter plugin for dynamically changing app icon and app icon batch number in the mobile platform. Supports only iOS (with version > 10.3).

Usage

To use this plugin, add flutter_dynamic_icon as a dependency in your pubspec.yaml file.

Getting Started

Check out the example directory for a sample app using flutter_dynamic_icon.

iOS Integration

Index

  • 2x - 120px x 120px
  • 3x - 180px x 180px

To integrate your plugin into the iOS part of your app, follow these steps

  1. First let us put a few images for app icons, they are
  2. These icons shouldn't be kept in Assets.xcassets folder, but outside. When copying to Xcode, you can select 'create folder references' or 'create groups', if not you will get and error when uploading the build to the AppStore saying: (Thanks to @nohli for this observation) TMS-90032: Invalid Image Path - - No image found at the path referenced under key 'CFBundleAlternateIcons':...

Here is my directory structure:

directory_structure

  1. Next, we need to setup the Info.plist
    1. Add Icon files (iOS 5) to the Information Property List
    2. Add CFBundleAlternateIcons as a dictionary, it is used for alternative icons
    3. Set 3 dictionaries under CFBundleAlternateIcons, they are correspond to teamfortress, photos, and chills
    4. For each dictionary, two properties — UIPrerenderedIcon and CFBundleIconFiles need to be configured
    5. If the sub-property UINewsstandIcon is showing under Icon files (iOS 5) and you don't plan on using it (it is intended for use with Newstand features), erase it or the app will get rejected upon submission on the App Store

Note that if you need it work for iPads, You need to add these icon declarations in CFBundleIcons~ipad as well. See here for more details.

Here is my Info.plist after adding Alternate Icons

Screenshot

info.plist

Raw

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>en</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIcons</key>
	<dict>
		<key>CFBundleAlternateIcons</key>
		<dict>
			<key>chills</key>
			<dict>
				<key>CFBundleIconFiles</key>
				<array>
					<string>chills</string>
				</array>
				<key>UIPrerenderedIcon</key>
				<false/>
			</dict>
			<key>photos</key>
			<dict>
				<key>CFBundleIconFiles</key>
				<array>
					<string>photos</string>
				</array>
				<key>UIPrerenderedIcon</key>
				<false/>
			</dict>
			<key>teamfortress</key>
			<dict>
				<key>CFBundleIconFiles</key>
				<array>
					<string>teamfortress</string>
				</array>
				<key>UIPrerenderedIcon</key>
				<false/>
			</dict>
		</dict>
		<key>CFBundlePrimaryIcon</key>
		<dict>
			<key>CFBundleIconFiles</key>
			<array>
				<string>chills</string>
			</array>
			<key>UIPrerenderedIcon</key>
			<false/>
		</dict>
	</dict>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>flutter_dynamic_icon_example</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>$(FLUTTER_BUILD_NAME)</string>
	<key>CFBundleSignature</key>
	<string>????</string>
	<key>CFBundleVersion</key>
	<string>$(FLUTTER_BUILD_NUMBER)</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIMainStoryboardFile</key>
	<string>Main</string>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UIViewControllerBasedStatusBarAppearance</key>
	<false/>
</dict>
</plist>

Now, you can call FlutterDynamicIcon.setAlternateIconName with the CFBundleAlternateIcons key as the argument to set that icon.

Dart/Flutter Integration

From your Dart code, you need to import the plugin and use it's static methods:

import 'package:flutter_dynamic_icon/flutter_dynamic_icon.dart';

try {
  if (await FlutterDynamicIcon.supportsAlternateIcons) {
    await FlutterDynamicIcon.setAlternateIconName("photos");
    print("App icon change successful");
    return;
  }
} on PlatformException {} catch (e) {}
print("Failed to change app icon");

...

// set batch number
try {
	await FlutterDynamicIcon.setApplicationIconBadgeNumber(9399);
} on PlatformException {} catch (e) {}

// gets currently set batch number
int batchNumber = FlutterDynamicIcon.getApplicationIconBadgeNumber();

Check out the example app for more details

Screenrecord

Showing App Icon change

Screenrecording of the example

Showing Batch number on app icon change in SpringBoard

Screenrecording of the example

Reference

This was made possible because this blog. I borrowed a lot of words from this blog. https://medium.com/ios-os-x-development/dynamically-change-the-app-icon-7d4bece820d2

flutter_dynamic_icon's People

Contributors

flucadetena avatar nohli avatar tastelessjolt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flutter_dynamic_icon's Issues

ITMS-90138: Your Info.plist contains the UINewsstandIcon sub-property under CFBundleIcons on submit to App Store

This is not really a bug, I'm just adding it here so anyone with the problem can solve it, and then I'll make a pull request to add this to the docs.

After everything the package works great, but after submitting the app to the AppStore, and getting a review I got this issue raised up:

ITMS-90138: Your Info.plist contains the UINewsstandIcon sub-property under CFBundleIcons, which is intended for use with Newstand features. To include Newsstand features, the Info.plist must include the UINewsstandApp=true Info.plist key.

SOLUTION:

This comes because when adding the "Icon Files" to the Info.plist, Xcode automatically adds a property "UINewsstandApp" next to "primary Icon".

Simply erase that property and resubmit. This will Solve The issue.

android support?

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

How to add icons for iPad (152x152, 167x167)?

Describe the bug

Dear Developer,

We identified one or more issues with a recent delivery for your app, (...). Your delivery was successful, but you may wish to correct the following issues in your next delivery:

ITMS-90892: Missing recommended icon - The bundle does not contain an alternate app icon for iPad of exactly '167x167' pixels, in .png format for iOS versions supporting iPad Pro. To support older operating systems, the icon may be required in the bundle outside of an asset catalog. Make sure the Info.plist file includes appropriate entries referencing the file. See https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleicons

ITMS-90892: Missing recommended icon - The bundle does not contain an alternate app icon for iPad of exactly '152x152' pixels, in .png format for iOS versions >= 10.0. To support older operating systems, the icon may be required in the bundle outside of an asset catalog. Make sure the Info.plist file includes appropriate entries referencing the file. See https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleicons

After you’ve corrected the issues, you can upload a new binary to App Store Connect.

Best regards,

The App Store Team

It worked fine without this warning before June 11th.

So far, I've tried to add the requested icon sizes under CFBundleIcons~ipad and name them differently, but didn't work.

On this day, also the following warning appeared:

ITMS-90890: Missing recommended icon - The bundle does not contain an alternate app icon for iPhone / iPod Touch of exactly '120x120' pixels, in .png format for iOS versions >= 10.0. To support older versions of iOS, the icon may be required in the bundle outside of an asset catalog. Make sure the Info.plist file includes appropriate entries referencing the file. See https://developer.apple.com/documentation/bundleresources/information_property_list/cfbundleicons

It was because I only had one 160x160 picture.png and got fixed by renaming it to [email protected] and adding [email protected] with 120x120 resolution.

Confused about what documentation means by 'some Android versions'

Just wanting to get clarity on what the documentation means when it says "Caution: Using this feature on some android versions will cause your app to crash (it will crash the first time you change the icon, next time it won't)" under known issues.

Is there an official list kept somewhere of the android versions that crash, or is it basically that ANY android version will crash? Just trying to get clarity so I can implement a UI warning for those on Android.

ITMS-90032: Invalid Image Path - - No image found at the path referenced under key 'CFBundleAlternateIcons': 'image1'

Whenever i upload build on app store it succeeds but after some time it gets rejected with the error message as in the tiltle.
Here is my info.plist
<key>CFBundleIcons</key> <dict> <key>CFBundleAlternateIcons</key> <dict> <key>image1</key> <dict> <key>CFBundleIconFiles</key> <array> <string>image1</string> </array> <key>UIPrerenderedIcon</key> <false/> </dict> </dict> <key>CFBundlePrimaryIcon</key> <dict> <key>CFBundleIconFiles</key> <array> <string>default</string> </array> <key>UIPrerenderedIcon</key> <false/> </dict> </dict>
and icons are placed int flutter->IOS->Runner->APP ICONS with name:
[email protected]
[email protected]
[email protected]
[email protected]
can someone guid me or is there something i'm missing.

Does not work when installing from ipa on physical device

Describe the bug
It works normally in the emulator, and when run directly on the physical device.
However, when I generate the ipa and install it on the device I receive an error.

To Reproduce
Steps to reproduce the behavior:
It even happens with the example app in this repository

Screenshots
error

  • Device: [iPhone SE-2]
  • OS: [iOS16.6]

Does not work anymore with ios 14

Describe the bug
Since ios 14, the plugin does not work. When I try to change the app icon, it is slow and it always shows in the popup my default app icon and nothing changes. Maybe the slowness is due to the fact it search for the proper icon and does not find it ?

Smartphone (please complete the following information):

  • Device: iphone Xr
  • OS: ios 14.0
  • Flutter version: 1.22.0-12.1.pre

Package giving error when building apk

I know this package doesn't support android but it is stoping me from building an apk with error.

FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
Execution failed for task ':flutter_dynamic_icon:verifyReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Android resource linking failed                                    
     /Users/elias/.gradle/caches/transforms-2/files-2.1/54f632c208d2043bf822966bc676d057/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/fontVariationSettings not found.
                                                                        
     /Users/elias/.gradle/caches/transforms-2/files-2.1/54f632c208d2043bf822966bc676d057/core-1.0.0/res/values/values.xml:57:5-88:25: AAPT: error: resource android:attr/ttcIndex not found.
                                                                        
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org                              
                                                                        
BUILD FAILED in 1m 41s           

Revert back to original Icon

Is your feature request related to a problem? Please describe.
I would like to be able to revert back to the original Icon

Describe the solution you'd like
We need a method that reverts the custom Icon

Afaik this should be possible by calling

UIApplication.sharedApplication setAlternateIconName:iconName

and setting the iconName to nil

I would suggest to add another flutter method that does this call with nil

App Icon No Longer Changing Instantly

I have a custom screen built that displays my alt icons. I tap on one & I get the popup with the icon image and message that it has been changed.

I then background my app and I do not see the change.

It's only when I completely rebuild from VSCode that I see the change.

I'm running Flutter v2.10.1. I was on v2.10.5 & thought the issue may have been there so I downgraded.

Xcode v13.3.1

iOS 15.4.1

iOS 15 displays successful but does not change

Describe the bug
A Dialog display saying the change was successful, but the icon change to an empty placeholder one

To Reproduce
on iOS 15, configure the project using following the project instructions

Expected behavior
A clear and concise description of what you expected to happen.

Error:

[default] +[LSApplicationProxy applicationProxyFor*] is not a supported method for getting the LSApplicationProxy for the current process, use +[LSBundleProxy bundleProxyForCurrentProcess] instead.
[default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]}
[default] Attempt to map database failed: permission was denied. This attempt will not be retried.
[db] Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]}
flutter: App icon change successful

Does not work on physical device

When I run it in the iOS emulator, the icons change without any problem. But when I run it on the real device, the icon does not change. Can you help me with these error codes?

+[LSApplicationProxy applicationProxyFor*] is not a supported method for getting the LSApplicationProxy for the current process, use +[LSBundleProxy bundleProxyForCurrentProcess] instead.

LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=66, _LSFunction=_LSServer_GetServerStoreForConnectionWithCompletionHandler}

Attempt to map database failed: permission was denied. This attempt will not be retried.

Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=66, _LSFunction=_LSServer_GetServerStoreForConnectionWithCompletionHandler}

Not working when google_sign_in plugin is present

Describe the bug
I'm not sure it's a bug in this plugin, just wanted help to understand a weird behavior and maybe come up with an alternative.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new flutter project
  2. Add flutter_dynamic_icon and make it work normally on iPhone emulator
  3. Add google_sign_in: ^5.2.3 (or any version) dependency to pubspec.yaml
  4. Run pod install inside ios folder
  5. Run the project again, FlutterDynamicIcon.supportsAlternateIcons() now returns false. If we skip the verification and call FlutterDynamicIcon.setAlternateIconName() directly, it returns PlatformException(Failed to set icon, Error Domain=NSCocoaErrorDomain Code=3328 "The requested operation couldn’t be completed because the feature is not supported.

I don't see how adding another totally unrelated plugin would cause this, investigating it a little further I noticed that adding google_sign_in actually installs 4 additional pods:

  • AppAuth (1.4.0)
  • GTMAppAuth (1.2.2)
  • GTMSessionFetcher (1.7.0)
  • GoogleSignIn (5.0.2)

Still, doesn't make sense to me.

Expected behavior
Icon should be changed normally

Screenshots
If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

  • Device: iPhone simulator
  • OS: iOS 15.0

Additional context
I'm running it in a Macbook with intel chip

badge support not working on android

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

FlutterDynamicIcon.setApplicationIconBadgeNumber(5);

Expected behavior
This should update the badger on both platforms( IOS and Android), it turns out that it only works on android

Smartphone (please complete the following information):

  • Device: [Samsung Galaxy A03]
  • OS: [e.g. Android]
  • Version [e.g. 10]

The app-icon is not changed in the multitasking app switcher

Currently, flutter-dynamic-icon is working well, but I am encountering an issue where the app icon itself is changed to Icon B, but in the multitasking app switcher, it still shows Icon A. I know this is due to Apple's device and can be fixed by restarting the device, but this is not feasible for users. Is there any feasible way to resolve this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.