Using Dependency Service we can Do this so first we start with interface creation in our portable projects.
public interface IAppIconSwitchService
{
Task SwitchAppIcon(string iconName);
}
and in MainPage.xaml
async void Xamarin_Button_Clicked(System.Object sender, System.EventArgs e)
{
var iconSwitcher = DependencyService.Get<IAppIconSwitchService>();
await iconSwitcher.SwitchAppIcon(null);
}
async void Maui_Button_Clicked(System.Object sender, System.EventArgs e)
{
var iconSwitcher = DependencyService.Get<IAppIconSwitchService>();
await iconSwitcher.SwitchAppIcon("MauiLogo");
}
using System;
using System.Threading.Tasks;
using AppIconUpdater;
using AppIconUpdater.iOS;
using UIKit;
using Xamarin.Forms;
[assembly: Xamarin.Forms.Dependency(typeof(AppIconSwitchService))]
namespace AppIconUpdater.iOS
{
public class AppIconSwitchService : IAppIconSwitchService
{
public async Task SwitchAppIcon(string iconName)
{
if (UIApplication.SharedApplication.SupportsAlternateIcons)
{
if (iconName == "MauiLogo")
await UIApplication.SharedApplication.SetAlternateIconNameAsync(iconName);
else
UIApplication.SharedApplication.SetAlternateIconName(null, (error) => { Console.WriteLine(error); });
}
}
}
}
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site. For more info:- Xamarin App Development
ReplyDelete