Scrungepipes
Scrungepipes

Reputation: 37581

How do you provide an icon for an action extension?

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?

Upvotes: 33

Views: 11815

Answers (7)

jrjian
jrjian

Reputation: 170

Greater than Xcode 14, the key has changed to Primary App Icon Set Name in the Build Settings section of the extension

Just add a icon into the Media assets and change it name "AppIconExtension"(whatevery like, do not duplicate the name)

Remove your extension, Restart your iphone。Install again.

enter image description here

Upvotes: 1

Muhammad Ahmad
Muhammad Ahmad

Reputation: 259

for Xcode 14, the key has changed to Primary App Icon Set Name in the Build Settings section of the extension

Upvotes: 2

Vitalii
Vitalii

Reputation: 4437

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 Primary App Icon Set Name (or Asset Catalog App Icon Set Name before Xcode 15) and enter the name of your icon.

enter image description here

  1. Build and run the extension.

Upvotes: 42

Jack
Jack

Reputation: 14329

We need a monochromatic icon for Extension application which has exactly same dimensions & type as we set on Appicon(Only name & icon type is differ). Firstly we need to include assets to the extension target

Step 1:- For adding assets click on extension scheme->Build phases ->Copy Bundle Resources ->Click + -> Add assets OR Just add by click on assets in your extension target membership.

refer below screen shot

enter image description here

enter image description here

Step 2:- Now for setting up extension App icon click on Extension application from targets area, Go to build settings ->Search Assets catalog compiler option ->Enter your App icon name

refer below screen shot

refer below screen shot

Upvotes: 9

Scrungepipes
Scrungepipes

Reputation: 37581

In order to get it to work its not enough to add the assets to the asset catalog - its additionally necessary to set the Asset Catalog compiler options of Build Settings section of the extension to specify the name of the app icon set within the asset catalog:

enter image description here

Upvotes: 19

Randy
Randy

Reputation: 4525

Got a lot of troubles trying to solve that problem but I eventually found a workaround (I don't like it, but it works):

I ended up installing the last version of Xcode 7. I opened my project with Xcode 7 and then I followed the steps provided in this answer: https://stackoverflow.com/a/27333408/3844377.

Then I ran my project from Xcode 8 and it worked like a charm.

Upvotes: 1

jamesk
jamesk

Reputation: 3877

The documentation for action extension icons isn't particularly helpful—try this answer, which provides a worked example, or this answer coupled with the discussion continued in chat.

For the icon itself, current guidance is as follows:

Use a template image for an action extension icon. A template image uses a mask to create an icon. Use black and white with appropriate transparency and antialiasing, and don’t include a drop shadow. Template images should be centered in an area measuring about 70px by 70px.

Upvotes: 5

Related Questions