mirror of
https://github.com/YTLitePlus/YTLitePlus.git
synced 2026-05-21 09:42:17 +00:00
Update AppIconOptionsController.m (test)
Untested implementation. Might not work.
This commit is contained in:
parent
22b896e389
commit
87151db562
1 changed files with 21 additions and 11 deletions
|
|
@ -107,11 +107,24 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)saveIcon {
|
- (void)saveIcon {
|
||||||
NSString *selectedIconPath = self.selectedIconIndex >= 0 ? self.appIcons[self.selectedIconIndex] : nil;
|
NSString *selectedIcon = self.selectedIconIndex >= 0 ? self.appIcons[self.selectedIconIndex] : nil;
|
||||||
if (selectedIconPath) {
|
if (selectedIcon) {
|
||||||
NSURL *iconURL = [NSURL fileURLWithPath:selectedIconPath];
|
NSString *iconName = [selectedIcon.lastPathComponent stringByDeletingPathExtension];
|
||||||
if ([[UIApplication sharedApplication] respondsToSelector:@selector(setAlternateIconName:completionHandler:)]) {
|
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
|
||||||
[[UIApplication sharedApplication] setAlternateIconName:selectedIconPath completionHandler:^(NSError * _Nullable error) {
|
NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
|
||||||
|
NSMutableDictionary *iconsDict = [infoDict objectForKey:@"CFBundleIcons"];
|
||||||
|
|
||||||
|
if (iconsDict) {
|
||||||
|
NSMutableDictionary *primaryIconDict = [iconsDict objectForKey:@"CFBundlePrimaryIcon"];
|
||||||
|
if (primaryIconDict) {
|
||||||
|
NSMutableArray *iconFiles = [primaryIconDict objectForKey:@"CFBundleIconFiles"];
|
||||||
|
[iconFiles addObject:iconName];
|
||||||
|
primaryIconDict[@"CFBundleIconFiles"] = iconFiles;
|
||||||
|
}
|
||||||
|
[infoDict setObject:iconsDict forKey:@"CFBundleIcons"];
|
||||||
|
[infoDict writeToFile:plistPath atomically:YES];
|
||||||
|
|
||||||
|
[[UIApplication sharedApplication] setAlternateIconName:iconName completionHandler:^(NSError * _Nullable error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
NSLog(@"Error setting alternate icon: %@", error.localizedDescription);
|
NSLog(@"Error setting alternate icon: %@", error.localizedDescription);
|
||||||
[self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"];
|
[self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"];
|
||||||
|
|
@ -121,13 +134,10 @@
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
NSLog(@"CFBundleIcons key not found in Info.plist");
|
||||||
[dict setObject:iconURL forKey:@"iconURL"];
|
|
||||||
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
|
|
||||||
[dict writeToFile:filePath atomically:YES];
|
|
||||||
|
|
||||||
[self showAlertWithTitle:@"Alternate Icon" message:@"Please restart the app to apply the alternate icon"];
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
NSLog(@"Selected icon path is nil");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue