Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions AlternateAppIcons/iOS/AlternateAppIcons.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0-ios</TargetFramework>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings>
<SupportedOSPlatformVersion>13.0</SupportedOSPlatformVersion>

<!--
Enable full trimming in Release mode.
To learn more, see: https://learn.microsoft.com/dotnet/core/deploying/trimming/trimming-options#trimming-granularity
-->
<TrimMode Condition="'$(Configuration)' == 'Release'">full</TrimMode>

<AppIcon>AppIcon</AppIcon>
</PropertyGroup>

<ItemGroup>
<AlternateAppIcon Include="AlternateAppIcons" />
</ItemGroup>
</Project>
128 changes: 128 additions & 0 deletions AlternateAppIcons/iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
namespace AlternateAppIcons;

using UserNotifications;

[Register ("AppDelegate")]
public class AppDelegate : UIApplicationDelegate {
UIColor blue = UIColor.FromRGB (81, 43, 212);
UIColor green = UIColor.FromRGB (119, 187, 65);
UILabel? label;
int badgeCount;

public override UIWindow? Window {
get;
set;
}

public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
// create a new window instance based on the screen size
Window = new UIWindow (UIScreen.MainScreen.Bounds);

// create a UIViewController with a single UILabel
var vc = new UIViewController ();

var stackView = new UIStackView (Window.Frame);
stackView.Axis = UILayoutConstraintAxis.Vertical;
stackView.Distribution = UIStackViewDistribution.FillEqually;

label = new UILabel () {
TextColor = blue,
TextAlignment = UITextAlignment.Center,
Text = "Hello, App Icon Switcher!",
AutoresizingMask = UIViewAutoresizing.All,
};
stackView.AddArrangedSubview (label);

var primaryIconButton = UIButton.FromType (UIButtonType.RoundedRect);
primaryIconButton.SetTitle ("Switch to primary icon", UIControlState.Normal);
primaryIconButton.SetTitleColor (blue, UIControlState.Normal);
primaryIconButton.TouchUpInside += async (sender, args) => await UsePrimaryIconAsync ();
primaryIconButton.Enabled = UIApplication.SharedApplication.SupportsAlternateIcons;
stackView.AddArrangedSubview (primaryIconButton);

var alternateIconButton = UIButton.FromType (UIButtonType.RoundedRect);
alternateIconButton.SetTitle ("Switch to alternate icon", UIControlState.Normal);
alternateIconButton.SetTitleColor (green, UIControlState.Normal);
alternateIconButton.TouchUpInside += async (sender, args) => await UseAlternateIconAsync ();
alternateIconButton.Enabled = UIApplication.SharedApplication.SupportsAlternateIcons;
stackView.AddArrangedSubview (alternateIconButton);

var incrementBadgeCount = UIButton.FromType (UIButtonType.RoundedRect);
incrementBadgeCount.SetTitle ("Increment badge count", UIControlState.Normal);
incrementBadgeCount.PrimaryActionTriggered += (sender, args) => SetBadgeCount (badgeCount + 1);
incrementBadgeCount.Enabled = UIApplication.SharedApplication.SupportsAlternateIcons;
stackView.AddArrangedSubview (incrementBadgeCount);

var decrementBadgeCount = UIButton.FromType (UIButtonType.RoundedRect);
decrementBadgeCount.SetTitle ("Decrement badge count", UIControlState.Normal);
decrementBadgeCount.PrimaryActionTriggered += (sender, args) => SetBadgeCount (badgeCount - 1);
decrementBadgeCount.Enabled = UIApplication.SharedApplication.SupportsAlternateIcons;
stackView.AddArrangedSubview (decrementBadgeCount);

vc.View!.AddSubview (stackView);
Window.RootViewController = vc;

// make the window visible
Window.MakeKeyAndVisible ();

return true;
}

void SetBadgeCount (int count)
{
if (count >= 0) {
if (OperatingSystem.IsIOSVersionAtLeast (16, 0)) {
UNUserNotificationCenter.Current.RequestAuthorization (UNAuthorizationOptions.Badge, (bool granted, NSError error) => {
if (granted) {
UNUserNotificationCenter.Current.SetBadgeCount (count, (error) => {
InvokeOnMainThread (() => {
if (error is null) {
label!.Text = $"Updated badge count to {count}";
badgeCount = count;
} else {
label!.Text = $"Updated to update badge count: {error}";
}
});
});
} else {
InvokeOnMainThread (() => {
label!.Text = $"Denied permission to the badge: {error}";
});
}
});
} else {
UIApplication.SharedApplication.ApplicationIconBadgeNumber = count;
badgeCount = count;
}
} else {
label!.Text = $"Can't decrement badge count to below 0.";
}
}

async Task UsePrimaryIconAsync ()
{
label!.Text = $"Switching to primary icon...";
try {
await UIApplication.SharedApplication.SetAlternateIconNameAsync (null);
label!.Text = "Using primary icon";
label!.TextColor = blue;
} catch (Exception e) {
label!.Text = $"Failed to switch to primary icon: {e.Message}";
label!.TextColor = UIColor.Red;
}
}

async Task UseAlternateIconAsync ()
{
label!.Text = $"Switching to alternate icon...";
try {
await UIApplication.SharedApplication.SetAlternateIconNameAsync ("AlternateAppIcons");
label!.Text = $"Using alternate icon {UIApplication.SharedApplication.AlternateIconName}";
label!.TextColor = green;
} catch (Exception e) {
label!.Text = $"Failed to switch to alternate icon: {e.Message}";
label!.TextColor = UIColor.Red;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"images": [
{
"scale": "2x",
"size": "20x20",
"idiom": "iphone",
"filename": "Icon40.png"
},
{
"scale": "3x",
"size": "20x20",
"idiom": "iphone",
"filename": "Icon60.png"
},
{
"scale": "2x",
"size": "29x29",
"idiom": "iphone",
"filename": "Icon58.png"
},
{
"scale": "3x",
"size": "29x29",
"idiom": "iphone",
"filename": "Icon87.png"
},
{
"scale": "2x",
"size": "40x40",
"idiom": "iphone",
"filename": "Icon80.png"
},
{
"scale": "3x",
"size": "40x40",
"idiom": "iphone",
"filename": "Icon120.png"
},
{
"scale": "2x",
"size": "60x60",
"idiom": "iphone",
"filename": "Icon120.png"
},
{
"scale": "3x",
"size": "60x60",
"idiom": "iphone",
"filename": "Icon180.png"
},
{
"scale": "1x",
"size": "20x20",
"idiom": "ipad",
"filename": "Icon20.png"
},
{
"scale": "2x",
"size": "20x20",
"idiom": "ipad",
"filename": "Icon40.png"
},
{
"scale": "1x",
"size": "29x29",
"idiom": "ipad",
"filename": "Icon29.png"
},
{
"scale": "2x",
"size": "29x29",
"idiom": "ipad",
"filename": "Icon58.png"
},
{
"scale": "1x",
"size": "40x40",
"idiom": "ipad",
"filename": "Icon40.png"
},
{
"scale": "2x",
"size": "40x40",
"idiom": "ipad",
"filename": "Icon80.png"
},
{
"scale": "1x",
"size": "76x76",
"idiom": "ipad",
"filename": "Icon76.png"
},
{
"scale": "2x",
"size": "76x76",
"idiom": "ipad",
"filename": "Icon152.png"
},
{
"scale": "2x",
"size": "83.5x83.5",
"idiom": "ipad",
"filename": "Icon167.png"
},
{
"scale": "1x",
"size": "1024x1024",
"idiom": "ios-marketing",
"filename": "Icon1024.png"
}
],
"properties": {},
"info": {
"version": 1,
"author": "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions AlternateAppIcons/iOS/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
{
"images": [
{
"scale": "2x",
"size": "20x20",
"idiom": "iphone",
"filename": "Icon40.png"
},
{
"scale": "3x",
"size": "20x20",
"idiom": "iphone",
"filename": "Icon60.png"
},
{
"scale": "2x",
"size": "29x29",
"idiom": "iphone",
"filename": "Icon58.png"
},
{
"scale": "3x",
"size": "29x29",
"idiom": "iphone",
"filename": "Icon87.png"
},
{
"scale": "2x",
"size": "40x40",
"idiom": "iphone",
"filename": "Icon80.png"
},
{
"scale": "3x",
"size": "40x40",
"idiom": "iphone",
"filename": "Icon120.png"
},
{
"scale": "2x",
"size": "60x60",
"idiom": "iphone",
"filename": "Icon120.png"
},
{
"scale": "3x",
"size": "60x60",
"idiom": "iphone",
"filename": "Icon180.png"
},
{
"scale": "1x",
"size": "20x20",
"idiom": "ipad",
"filename": "Icon20.png"
},
{
"scale": "2x",
"size": "20x20",
"idiom": "ipad",
"filename": "Icon40.png"
},
{
"scale": "1x",
"size": "29x29",
"idiom": "ipad",
"filename": "Icon29.png"
},
{
"scale": "2x",
"size": "29x29",
"idiom": "ipad",
"filename": "Icon58.png"
},
{
"scale": "1x",
"size": "40x40",
"idiom": "ipad",
"filename": "Icon40.png"
},
{
"scale": "2x",
"size": "40x40",
"idiom": "ipad",
"filename": "Icon80.png"
},
{
"scale": "1x",
"size": "76x76",
"idiom": "ipad",
"filename": "Icon76.png"
},
{
"scale": "2x",
"size": "76x76",
"idiom": "ipad",
"filename": "Icon152.png"
},
{
"scale": "2x",
"size": "83.5x83.5",
"idiom": "ipad",
"filename": "Icon167.png"
},
{
"scale": "1x",
"size": "1024x1024",
"idiom": "ios-marketing",
"filename": "Icon1024.png"
}
],
"properties": {},
"info": {
"version": 1,
"author": "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions AlternateAppIcons/iOS/Entitlements.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
Loading