Update AppIconOptionsController (revamp saveIcon)

This commit is contained in:
arichornlover 2024-04-16 16:08:21 -05:00 committed by GitHub
parent ccfde3916e
commit cabb3aa95f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -105,16 +105,26 @@
- (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 {