Skip to content

Commit

Permalink
Update AppIconOptionsController (revamp saveIcon)
Browse files Browse the repository at this point in the history
  • Loading branch information
arichornlover authored Apr 16, 2024
1 parent ccfde39 commit cabb3aa
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions Sources/AppIconOptionsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit cabb3aa

Please sign in to comment.