Update AppIconOptionsController.m

This commit is contained in:
aric3435 2024-10-22 17:13:05 -05:00 committed by GitHub
parent 9f6ec2d176
commit f124ce6a2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,37 +2,48 @@
#import <YouTubeHeader/YTAssetLoader.h>
@interface AppIconOptionsController () <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) NSArray<NSString *> *appIcons;
@property (assign, nonatomic) NSInteger selectedIconIndex;
@end
@implementation AppIconOptionsController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Change App Icon";
self.selectedIconIndex = -1;
[self setupTableView];
[self setupBackButton];
[self loadAppIcons];
if (![UIApplication sharedApplication].supportsAlternateIcons) {
NSLog(@"Alternate icons are not supported on this device.");
}
}
- (void)setupTableView {
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
}
- (void)setupBackButton {
self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.backButton setImage:[UIImage customBackButtonImage] forState:UIControlStateNormal];
[self.backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBackButton = [[UIBarButtonItem alloc] initWithCustomView:self.backButton];
self.navigationItem.leftBarButtonItem = customBackButton;
}
- (void)loadAppIcons {
NSString *path = [[NSBundle mainBundle] pathForResource:@"uYouPlus" ofType:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:path];
self.appIcons = [bundle pathsForResourcesOfType:@"png" inDirectory:@"AppIcons"];
if (![UIApplication sharedApplication].supportsAlternateIcons) {
NSLog(@"Alternate icons are not supported on this device.");
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
@ -87,10 +98,8 @@
[self showAlertWithTitle:@"Error" message:@"No icon selected"];
return;
}
NSString *selectedIcon = self.appIcons[self.selectedIconIndex];
NSString *iconName = [selectedIcon.lastPathComponent stringByDeletingPathExtension];
[[UIApplication sharedApplication] setAlternateIconName:iconName completionHandler:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error setting alternate icon: %@", error.localizedDescription);