Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you provide an icon for an action extension?

Tags:

All the extension types use the containing app's icon, with the exception of action extension. The Apple documentation says this:

In iOS, a custom Action extension uses a template image version of its containing app’s icon, which you must provide.

However it does not say how you must provide the icon. It says:

For information on how to add an icon to your app extension, see Creating an Asset Catalog and Adding an App Icon Set or Launch Image Set.

But the links to "Creating an Asset Catalog" and "Adding an App Icon" documentation are links to how to add an icon for an app, they don't contain a section on how to add an icon specifically for an action extension.

The extension target does not contain an app icon section in the XCode general settings (unlike an app), so its icon presumably must be added via an asset catalog. However, even after I added an app icon image set to my extension's asset catalog, the extension's icon is still not appearing.

How am I supposed to add an icon for an action extension? And if it's via its asset catalog then why is that not working when I've added an icon image set to the asset catalog?

like image 853
Gruntcakes Avatar asked Aug 17 '16 16:08

Gruntcakes


1 Answers

First, you need to have an asset catalog. You may already have this but if you don't, this is easy to create.

  1. Click on the group that contains the extension files.

  2. From the File menu, select New > File....

  3. In the iOS section, click on Asset Catalog and then click Next.


Second, we need to add the app icons to our project. Note that the icons must have a transparent background. If you try to use icons with a solid background, iOS will not display the icon.

  1. Click the + button and choose App Icons & Launch Images > New iOS App Icon.

    enter image description here

  2. By default, Xcode will call the icon AppIcon but it will also warn you that this name is in use. To remove this warning, choose a different name (e.g. AppIconExtension-iOS).

  3. Drag your icons into the 60px placeholder. You will also need 120x120 (aka @2x) and 180x180px (aka @3x) icons. You can create additional icons if you want but these are not necessary.

    enter image description here


Third, you need to tell Xcode to use the icon when building the extension.

  1. In the Project Navigator, select your project at the top of the tree.

  2. Select your extension as the Target and select Build Settings.

  3. Search for Asset Catalog App Icon Set Name and enter the name of your icon.

    enter image description here

  4. Build and run the extension.

like image 133
Vitalii Avatar answered Sep 16 '22 13:09

Vitalii