The project needs to change the background color of statusBar, but iOS 13 statusBar cannot be found. KVC [[[UIApplication sharedApplication] valueForKey:@”statusBarWindow”] valueForKey:@”statusBar”] crashes.
Add a statusBar for iOS 13:
-(UIView *)statusBarUIview{
if(@available(iOS 13,*)){
int tag = 13004352;
UIWindow *window = [UIApplication sharedApplication].delegate.window;
UIView *view = [window viewWithTag:tag];
if (view) {
return view;
}else{
CGRect statusBarRect = [UIApplication sharedApplication].statusBarFrame;
UIView *statusBarView = [[UIView alloc]initWithFrame:statusBarRect];
statusBarView.tag = tag;
[window addSubview:statusBarView];
returnstatusBarView; }}else{
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) {
returnstatusBar; }}return nil;
}
Copy the code
Before iOS 13, the same method was used. After iOS 13, you can manually configure one.