Search code examples
xamarin.formsxamarin.iosvisual-studio-2022

Xamarin Forms, IOS project, application icon does not work


I'm trying to add an icon to the Xamarin iOS app using Assets.xcassets and also I tried adding an .ico to the manifest in the iOS project settings but it doesn't work because I have the default Xamarin icon:

I don't have any particular error message referring to missing images or anything else in the build windows, debug or in the xamarin logs (Help/Xamarin/open logs).

I also tried to modify the Info.plist file:

<key>XSAppIconAssets</key>
    <string>Assets.xcassets/AppIcon.appiconset</string>
    <key>UIMainStoryboardFile</key>
    <string>LaunchScreen</string>
  <key>CFBundleIconName</key>
  <string>AppIcon</string>

  <key>CFBundleIcons</key>
  <dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
      <key>CFBundleIconFiles</key>
      <array>
        <string>20.png</string>
        <string>29.png</string>
        <string>40.png</string>
        <string>401.png</string>
        <string>402.png</string>
        <string>58.png</string>
        <string>581.png</string>
        <string>60.png</string>
        <string>76.png</string>
        <string>80.png</string>
        <string>801.png</string>
        <string>87.png</string>
        <string>120.png</string>
        <string>1201.png</string>
        <string>152.png</string>
        <string>167.png</string>
        <string>180.png</string>
        <string>1024.png</string>
      </array>
    </dict>
  </dict>

    <key>CFBundleIcons~ipad</key>
  <dict>
    <key>CFBundlePrimaryIcon</key>
    <dict>
      <key>CFBundleIconFiles</key>
      <array>
        <string>20.png</string>
        <string>29.png</string>
        <string>40.png</string>
        <string>401.png</string>
        <string>402.png</string>
        <string>58.png</string>
        <string>581.png</string>
        <string>60.png</string>
        <string>76.png</string>
        <string>80.png</string>
        <string>801.png</string>
        <string>87.png</string>
        <string>120.png</string>
        <string>1201.png</string>
        <string>152.png</string>
        <string>167.png</string>
        <string>180.png</string>
        <string>1024.png</string>
      </array>
    </dict>
  </dict>

And there I have no icon at all.

What am I doing wrong?

I am using Visual Studio 2022 v17.4.1 (Windows)

steps to reproduce the error :

  1. create a mobile application project (xamarin forms)
  2. add the images in the Assets.xcassets (they are well in the .csproj file like this :)
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\1024.png">
    <Visible>false</Visible>
</ImageAsset>
  1. add the .ico image to the ios project
  2. start the project on an iphone ios v15.7.1
  3. default xamarin icon !
  4. modify the info.plist, clean, regenerate
  5. no icon !

I expect my application icon to appear on the phone


Solution

  • You don't need to modify the Info.plist file, you can refer to the following steps:

    1. Create a new Xamarin.Forms project
    2. In your Solution Explorer directory, there is an Asset Catalogs folder in the iOS project, open the Assets file in this folder
    3. Replace the default icons of all sizes in Applcon, and check whether the image name in the .csproj file is correct.
    4. Build your app. If you have installed the app before, you need to uninstall it and reinstall it.

    For more details, you can refer to the official documentation: Application Icons in Xamarin.iOS | Microsof

    Update

    According to the comments, you used Hot Restart. Hot Restart will have some restrictions, one of which is: Asset Catalogs are currently not supported. When using Hot Restart, your app will show the default icon and launch screen for Xamarin apps. When paired to a Mac, or developing on a Mac, your Asset Catalogs will work.