From cabb3aa95fb177d99e5ea7a8804d59bd32cda052 Mon Sep 17 00:00:00 2001 From: arichornlover <78001398+arichornlover@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:08:21 -0500 Subject: [PATCH] Update AppIconOptionsController (revamp saveIcon) --- Sources/AppIconOptionsController.m | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Sources/AppIconOptionsController.m b/Sources/AppIconOptionsController.m index 064f6c46fc..8bfc206f19 100644 --- a/Sources/AppIconOptionsController.m +++ b/Sources/AppIconOptionsController.m @@ -105,16 +105,26 @@ - (void)resetIcon { - (void)saveIcon { NSString *selectedIconPath = self.selectedIconIndex >= 0 ? self.appIcons[self.selectedIconIndex] : nil; - - [[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) { - if (error) { - NSLog(@"Error setting alternate icon: %@", error.localizedDescription); - [self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"]; + if (selectedIconPath) { + NSURL *iconURL = [NSURL fileURLWithPath:selectedIconPath]; + if ([[UIApplication sharedApplication] respondsToSelector:@selector(setAlternateIconName:completionHandler:)]) { + [[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) { + if (error) { + NSLog(@"Error setting alternate icon: %@", error.localizedDescription); + [self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"]; + } else { + NSLog(@"Alternate icon set successfully"); + [self showAlertWithTitle:@"Success" message:@"Alternate icon set successfully"]; + } + }]; } else { - NSLog(@"Alternate icon set successfully"); - [self showAlertWithTitle:@"Success" message:@"Alternate icon set successfully"]; + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + [dict setObject:iconURL forKey:@"iconURL"]; + [dict writeToFile:[[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"] atomically:YES]; + + [self showAlertWithTitle:@"Alternate Icon" message:@"Please restart the app to apply the alternate icon"]; } - }]; + } } - (void)showAlertWithTitle:(NSString *)title message:(NSString *)message {