简体   繁体   中英

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:

It says:

However, even after I added an app icon image set to my extension's asset catalog, the extension's icon is still not appearing.

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?

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 .

    在此处输入图片说明

  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 (eg 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.

    在此处输入图片说明


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.

    在此处输入图片说明

  4. Build and run the extension.

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:

在此处输入图片说明

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

在此处输入图片说明

在此处输入图片说明

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

请参阅下面的屏幕截图

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.

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.

对于 Xcode 15,扩展的 Build Settings 部分中的键已更改为“ Primary App Icon Set Name<\/code> ”

"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM