Skip to content

Commit

Permalink
feat(all): 删除repairException方法,由主动调用修改为静默执行
Browse files Browse the repository at this point in the history
  • Loading branch information
internetWei committed Jan 21, 2021
1 parent 9d47f20 commit e270539
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 36 deletions.
20 changes: 3 additions & 17 deletions Demo/LLDynamicLaunchScreen/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,21 @@ - (void)viewDidLoad {
[button addTarget:self action:@selector(buttonEvent) forControlEvents:UIControlEventTouchUpInside];

UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
[button1 setTitle:@"修复异常" forState:UIControlStateNormal];
[button1 setTitle:@"恢复如初" forState:UIControlStateNormal];
[button1 setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
button1.backgroundColor = [UIColor colorWithRed:14.0 / 255.0 green:144.0 / 255.0 blue:1.0 alpha:1.0];
[self.view addSubview:button1];
button1.frame = CGRectMake((screenWidth - 220) / 2.0, CGRectGetMaxY(button.frame) + 40.0, 220, 80);
[button1 addTarget:self action:@selector(button1Event) forControlEvents:UIControlEventTouchUpInside];

UIButton *button2 = [UIButton buttonWithType:UIButtonTypeSystem];
[button2 setTitle:@"恢复如初" forState:UIControlStateNormal];
[button2 setTitle:@"恢复指定启动图" forState:UIControlStateNormal];
[button2 setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
button2.backgroundColor = [UIColor colorWithRed:14.0 / 255.0 green:144.0 / 255.0 blue:1.0 alpha:1.0];
[self.view addSubview:button2];
button2.frame = CGRectMake((screenWidth - 220) / 2.0, CGRectGetMaxY(button1.frame) + 40.0, 220, 80);
[button2 addTarget:self action:@selector(button2Event) forControlEvents:UIControlEventTouchUpInside];

UIButton *button3 = [UIButton buttonWithType:UIButtonTypeSystem];
[button3 setTitle:@"恢复指定启动图" forState:UIControlStateNormal];
[button3 setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
button3.backgroundColor = [UIColor colorWithRed:14.0 / 255.0 green:144.0 / 255.0 blue:1.0 alpha:1.0];
[self.view addSubview:button3];
button3.frame = CGRectMake((screenWidth - 220) / 2.0, CGRectGetMaxY(button2.frame) + 40.0, 220, 80);
[button3 addTarget:self action:@selector(button3Event) forControlEvents:UIControlEventTouchUpInside];

UILabel *alertLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
self.alertLabel = alertLabel;
alertLabel.center = self.view.center;
Expand All @@ -78,18 +70,12 @@ - (void)buttonEvent {
}

- (void)button1Event {
[LLDynamicLaunchScreen repairException];

[self showAlertView:@"修复启动图异常,APP即将退出"];
}

- (void)button2Event {
[LLDynamicLaunchScreen restoreAsBefore];

[self showAlertView:@"启动图已恢复,APP即将退出"];
}

- (void)button3Event {
- (void)button2Event {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请选择替换方式" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"恢复浅色竖屏启动图" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[LLDynamicLaunchScreen replaceLaunchImage:nil launchImageType:LLLaunchImageTypeVerticalLight compressionQuality:0.8 validation:nil];
Expand Down
8 changes: 0 additions & 8 deletions LLDynamicLaunchScreen/LLDynamicLaunchScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ typedef NS_ENUM(NSInteger, LLLaunchImageType) {
+ (nullable UIImage *)launchImageFromType:(LLLaunchImageType)launchImageType;


/**
修复启动图不显示等异常情况
@discussion 此操作是安全的,不会丢失已修改的启动图
*/
+ (void)repairException;


/**
将所有启动图恢复为默认启动图
Expand Down
26 changes: 15 additions & 11 deletions LLDynamicLaunchScreen/LLDynamicLaunchScreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ + (void)didFinishLaunching {
}
}
} identifier:NSStringFromSelector(@selector(didFinishLaunching))];

[self repairException];
}

+ (void)initialize {
Expand All @@ -71,6 +73,7 @@ + (void)initialize {
[versionDictionary setObject:@"YES" forKey:NSStringFromSelector(@selector(didFinishLaunching))];
[versionDictionary setObject:@"YES" forKey:NSStringFromSelector(@selector(initialization))];
[versionDictionary setObject:@"YES" forKey:NSStringFromSelector(@selector(backupSystemLaunchImage))];
[versionDictionary setObject:@"YES" forKey:NSStringFromSelector(@selector(repairException))];

[NSUserDefaults.standardUserDefaults setObject:versionDictionary.copy forKey:launchImageVersionIdentifier];

Expand Down Expand Up @@ -157,19 +160,20 @@ + (void)replaceHorizontalLaunchImage:(nullable UIImage *)horizontalImage {
}

+ (void)repairException {
if (doesExistsOriginLaunchImage()) {
NSDictionary *modifyDictionary = [NSUserDefaults.standardUserDefaults objectForKey:launchImageModifyIdentifier];
for (NSString *key in modifyDictionary) {
NSString *isModify = modifyDictionary[key];
if ([isModify isEqualToString:@"NO"]) {
[self replaceLaunchImage:nil launchImageType:LaunchImageTypeFromLaunchImageName(key) compressionQuality:0.8 validation:nil];
[self launchImageIsNewVersion:^{
if (doesExistsOriginLaunchImage()) {
NSDictionary *modifyDictionary = [NSUserDefaults.standardUserDefaults objectForKey:launchImageModifyIdentifier];
for (NSString *key in modifyDictionary) {
NSString *isModify = modifyDictionary[key];
if ([isModify isEqualToString:@"NO"]) {
[self replaceLaunchImage:nil launchImageType:LaunchImageTypeFromLaunchImageName(key) compressionQuality:0.8 validation:nil];
}
}
launchImage_repairException = NO;
} else {
launchImage_repairException = YES;
}

launchImage_repairException = NO;
} else {
launchImage_repairException = YES;
}
} identifier:NSStringFromSelector(@selector(repairException))];
}

+ (void)restoreAsBefore {
Expand Down

0 comments on commit e270539

Please sign in to comment.