Skip to content

Commit cabb3aa

Browse files
Update AppIconOptionsController (revamp saveIcon)
1 parent ccfde39 commit cabb3aa

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

Sources/AppIconOptionsController.m

+18-8
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,26 @@ - (void)resetIcon {
105105

106106
- (void)saveIcon {
107107
NSString *selectedIconPath = self.selectedIconIndex >= 0 ? self.appIcons[self.selectedIconIndex] : nil;
108-
109-
[[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) {
110-
if (error) {
111-
NSLog(@"Error setting alternate icon: %@", error.localizedDescription);
112-
[self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"];
108+
if (selectedIconPath) {
109+
NSURL *iconURL = [NSURL fileURLWithPath:selectedIconPath];
110+
if ([[UIApplication sharedApplication] respondsToSelector:@selector(setAlternateIconName:completionHandler:)]) {
111+
[[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) {
112+
if (error) {
113+
NSLog(@"Error setting alternate icon: %@", error.localizedDescription);
114+
[self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"];
115+
} else {
116+
NSLog(@"Alternate icon set successfully");
117+
[self showAlertWithTitle:@"Success" message:@"Alternate icon set successfully"];
118+
}
119+
}];
113120
} else {
114-
NSLog(@"Alternate icon set successfully");
115-
[self showAlertWithTitle:@"Success" message:@"Alternate icon set successfully"];
121+
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
122+
[dict setObject:iconURL forKey:@"iconURL"];
123+
[dict writeToFile:[[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"] atomically:YES];
124+
125+
[self showAlertWithTitle:@"Alternate Icon" message:@"Please restart the app to apply the alternate icon"];
116126
}
117-
}];
127+
}
118128
}
119129

120130
- (void)showAlertWithTitle:(NSString *)title message:(NSString *)message {

0 commit comments

Comments
 (0)