[绍棠] iOS13 适配

1、iOS13 DeviceToken有变化

- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 13) {

        if (![deviceToken isKindOfClass:[NSData class]]) return;

        const unsigned *tokenBytes = [deviceToken bytes];

        NSString *hexToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",

                              ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),

                              ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),

                              ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];

        NSLog(@"deviceToken:%@",hexToken);

    } else {

        NSString *tokenString = [[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""];

        tokenString = [tokenString stringByReplacingOccurrencesOfString: @">" withString: @""] ;

        tokenString = [tokenString stringByReplacingOccurrencesOfString: @" " withString: @""];

        NSLog(@"My token is: %@", tokenString);            

    }

2.iOS13 UISearchBar显示问题

黑线处理crash

之前为了处理搜索框的黑线问题会遍历后删除UISearchBarBackground,在iOS13会导致UI渲染失败crash;解决办法是设置UISearchBarBackground的layer.contents为nil

for (UIView *view in _searchBar.subviews) {

        if ([view isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {

            [view removeFromSuperview];

            break;

        }

        // for later iOS7.0(include)

        if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count > 0) {

            [[view.subviews objectAtIndex:0] removeFromSuperview];

            break;

        }

    }

3.iOS13 presentViewController和之前弹出的样式不一样

解决方法:

ViewController *vc = [[ViewController alloc] init]; vc.title = @"presentVC";

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];

nav.modalPresentationStyle = UIModalPresentationFullScreen;

[self.navigationController presentViewController:nav animated:YES completion:^{

}];

4. iOS13 UIImagePickerController全屏显示

UIImagePickerController *pickerController = [[UIImagePickerController alloc]init];

pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

pickerController.mediaTypes =@[(NSString*)kUTTypeMovie];

pickerController.allowsEditing = YES;

pickerController.delegate = self;

pickerController.videoMaximumDuration = 15.0;//视频最长长度

pickerController.modalPresentationStyle = UIModalPresentationOverFullScreen;

[self.navigationController presentViewController:pickerController animated:YES completion:nil];

发布了179 篇原创文章 · 获赞 24 · 访问量 16万+

猜你喜欢

转载自blog.csdn.net/happyshaotang2/article/details/101104376