适配Xcode11 && iOS13遇到的坑,持续更新···
1.缺失libstdc-6.0.9
libstdc-6.0.9 文件下载
下载后把1、2、3、4文件夹里的文件拖到Xcode以下对应的目录
1./Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/
2./Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/
3./Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/
4./Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/
2.-[_UINavigationBarContentView setLayoutMargins:],在Xcode 11中,我们无法使用Material来构建应用。错误信息如下:
*** Assertion failure in -[_UINavigationBarContentView setLayoutMargins:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3899.22.15/_UINavigationBarContentView.m:703
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Client error attempting to change layout margins of a private view'
*** First throw call stack:
(0x1ae7b098c 0x1ae4d90a4 0x1ae6b2d1c 0x1aeae88f4 0x1b1f09d04 0x1008adb34 0x1b2c49270 0x1b1edef98 0x1b51355f8 0x1b5139e28 0x1b2c35524 0x1b2113ccc 0x1b2113f00 0x1b211d5a4 0x1b21b8c24 0x1b211a5c8 0x1b2c40048 0x1b2c3fe28 0x1b2c3fe28 0x1b2c3fe28 0x1b2c341d4 0x1aea8830c 0x1b2c340d8 0x1b2c429c4 0x1b2c07bd4 0x1b21d5d94 0x1b21dd9d4 0x1b22ea070 0x1b21dd964 0x1b2c3b9c0 0x1b21dd7cc 0x1b20d5bf4 0x1b27c7b98 0x1b27b77c0 0x1b27d5b28 0x1ae72e614 0x1ae72ddb4 0x1ae729030 0x1ae7288bc 0x1b8594328 0x1b27be6d4 0x100b5edbc 0x1ae5b3460)
libc++abi.dylib: terminating with uncaught exception of type NSException
在iOS 13上,不允许更改私有视图的布局边距。因此,扩展框架以消除布局边距可以作为替代解决方案。实测在iPhone7 iOS12.4.1不会报错,而在iPhone X 13.1会报错
swift语言解决方案:
for view in subviews {
if #available(iOS 13.0, *) {
let margins = view.layoutMargins
var frame = view.frame
frame.origin.x = -margins.left
frame.size.width += (margins.left + margins.right)
view.frame = frame
} else {
view.layoutMargins = .zero
}
}
oc语言解决方案:
if (@available(iOS 13.0, *)) {
UIEdgeInsets margins = view.layoutMargins;
CGRect frame = view.frame;
frame.origin.x = -margins.left;
frame.origin.y = -margins.top;
frame.size.width += (margins.left + margins.right);
frame.size.height += (margins.top + margins.bottom);
view.frame = frame;
}else {
view.layoutMargins = UIEdgeInsetsZero;
}
3.+[_LSDefaults sharedInstance] 崩溃问题
友盟SDK出现问题,更新即可。终端执行:
pod update
注意,更新后需要将代码中的引用由之前的#import "UMCommon.h"
更换为#import <UMCommon/UMCommon.h>
4. 模态弹出presentViewController默认交互改变
iOS 13 的presentViewController
默认有视差效果,模态出来的界面现在默认都下滑返回。 一些页面必须要点确认才能消失的,需要适配。如果项目中页面高度全部是屏幕尺寸,那么多出来的导航高度会出现问题。
UIViewController
增加一个了属性isModalInPresentation
,默认为false
,当该属性为false
时,用户下拉可以dismiss
控制器,为true
时,下拉不可以dismiss
控制器。
会出现这种情况是主要是因为我们之前对UIViewController
里面的一个属性,即modalPresentationStyle
(该属性是控制器在模态视图时将要使用的样式)没有设置需要的类型。在iOS13中modalPresentationStyle
的默认改为UIModalPresentationAutomatic
,而在之前默认是UIModalPresentationFullScreen
。
这个不受Xcode版本的影响,只要是iOS13的系统,没有显式设置modalPresentationStyle
,就会有这个问题。
我们只需要把UIModalPresentationStyle
设置为
UIModalPresentationFullScreen
即可。即添加下面这行代码:
nav.modalPresentationStyle = UIModalPresentationFullScreen;
ViewController *vc = [[ViewController alloc] init];
vc.title = @"presentVC";
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:nav animated:YES completion:nil];
5.MPMoviePlayerController在iOS13中正式完全废弃
MPMoviePlayerController is no longer available. Use AVPlayerViewController in AVKit.
在iOS13中对于MPMoviePlayerController
使用的废弃,请使用AVKit
中的AVPlayerViewController
来达到播放的目的。
AVAsset *asset = [AVAsset assetWithURL:videoURL];
self.item=[AVPlayerItem playerItemWithAsset:asset];
//设置流媒体视频路径
//self.item=[AVPlayerItem playerItemWithURL:movieURL];
//设置AVPlayer中的AVPlayerItem
self.player=[AVPlayer playerWithPlayerItem:self.item];
//初始化layer 传入player
AVPlayerLayer *layer=[AVPlayerLayer playerLayerWithPlayer:self.player];
//设置layer的属性
layer.videoGravity = AVLayerVideoGravityResizeAspectFill;
layer.contentsScale = [UIScreen mainScreen].scale;
layer.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height/2);
layer.backgroundColor=[UIColor greenColor].CGColor;
//将视频的layer添加到视图的layer中
//[self.layer addSublayer:layer];
//替换AVPlayer中的AVPlayerItem
//[self.player replaceCurrentItemWithPlayerItem:self.item];
//监听status属性,注意监听的是AVPlayerItem
[self.item addObserver:self forKeyPath:@"loadedTimeRanges" options:NSKeyValueObservingOptionNew context:nil];
//监听loadedTimeRanges属性
[self.item addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
//moviewPlayer就是一个AVPlayerViewController
self.moviePlayer=[[AVPlayerViewController alloc]init];
self.moviePlayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
//设置AVPlayerViewController的player
self.moviePlayer.player=self.player;
self.player.accessibilityElementsHidden = YES;
self.moviePlayer.showsPlaybackControls = NO;
//把AVPlayerViewController的view添加到UIViewController的view中
[self addSubview:self.moviePlayer.view];
self.moviePlayer.view.frame=self.frame;
6.iOS13 解决 TabBar 选中文字颜色为蓝色问题
只需要设置UITabBarItem
的未选中颜色即可
[[UITabBar appearance] setUnselectedItemTintColor:[UIColor whiteColor]];
该方法设置的是UITabBar
的Item
未选中颜色,只需要将白色修改为你所需要的颜色即可,原本设置过的选中样式颜色会正常显示
因为该方法在 iOS13 以上才生效,所以适配了低版本的话可以加个条件判断
if (@available(iOS 13.0, *)) {
[[UITabBar appearance] setUnselectedItemTintColor:[UIColor whiteColor]];
}
因为只有 iOS13 才会出现这个问题,所以我直接判断是不是 iOS13 以后的系统了,适配 iOS13 遇到了很多坑,希望记录下来能帮助更多的人