1.首先 Xcode 升级后就是一些警告
如:
The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions for this platform is 9.0 to 14.0
每次升级 Xcode,苹果提高了最低版本,基本都会有这个警告
解决:删除 Pods、 Podfile.lock、xcworkspace 文件,然后重新 pod install,
或者直接在 Podfile 文件最后添加判断,然后 pod install
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 10.0
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
end
end
end
end
2.iOS14 隐私适配及部分解决方案
参考:iOS14 隐私适配及部分解决方案
或者:iOS 常用权限的获取及基本使用
3. UITableViewCell 添加子控件
需要使用 [cell.contentView addSubview:];
的方式添加
4. UITableViewHeaderFooterView 设置透明背景无效
由于 iOS 14 新增 backgroundConfiguration
方式修改背景
if #available(iOS 14.0, *) {
self.backgroundConfiguration = UIBackgroundConfiguration.clear()
} else {
// Fallback on earlier versions
}
5.UICollectionViewCell gestureRecognizers 为空
如果有用到此方法需要注意,比如在这个 bug 就出现了问题
iOS 14 前会有 UILongPressGestureRecognizer
iOS 14 后为空
6. UIWebView 禁止使用问题
cd 到工程根目录,全局搜索工程是否含有
grep -r UIWebView .
IPA 包搜索:
IPA:
cd payload/xxx.app
nm ./myapp | grep UIWebView
包含的字符
strings ./* | grep 'UIWebView'
7.keyWindow 获取
UIApplication.shared.keyWindow
在 iOS 13 就已经废弃了
可以这样获取
// 方式1
if #available(iOS 13.0, *) {
let keyWindow = UIApplication.shared.connectedScenes
.filter({ $0.activationState == .foregroundActive })
.map({ $0 as? UIWindowScene })
.compactMap({ $0 })
.first?.windows
.filter({ $0.isKeyWindow }).first
} else {
// Fallback on earlier versions
let keyWindow = UIApplication.shared.keyWindow
}
// 方式2
let keyWindow = UIApplication.shared.windows.filter { $0.isKeyWindow }.first
// 方式3
let keyWindow = UIApplication.shared.windows.first { $0.isKeyWindow }
8. Mac 升级到 Big Sur, Homebrew 警告, 报错
Traceback (most recent call last):
11: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `<main>'
10: from /usr/local/Homebrew/Library/Homebrew/brew.rb:23:in `require_relative'
9: from /usr/local/Homebrew/Library/Homebrew/global.rb:37:in `<top (required)>'
8: from /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
7: from /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
6: from /usr/local/Homebrew/Library/Homebrew/os.rb:3:in `<top (required)>'
5: from /usr/local/Homebrew/Library/Homebrew/os.rb:21:in `<module:OS>'
4: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:58:in `prerelease?'
3: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:24:in `version'
2: from /usr/local/Homebrew/Library/Homebrew/os/mac.rb:24:in `new'
1: from /usr/local/Homebrew/Library/Homebrew/os/mac/version.rb:26:in `initialize'
/usr/local/Homebrew/Library/Homebrew/version.rb:368:in `initialize': Version value must be a string; got a NilClass () (TypeError)
解决:brew update-reset
升级到最新版即可
参考
9.Ignoring ffi-1.12.2 because its extensions are not built. Try: gem pristine ffi --version 1.12.2
上面虽然解决了问题,但还会有多余的打印信息或警告。
根据提示进行 gem pristine ffi --version 1.12.2
但是发现没有作用,我们需要给上权限即可:
sudo gem pristine ffi --version 1.12.2
10.粘贴板设置字符串为空微信分享无法拉起分享列表
目前不想让粘贴板提示的方式就是进入 app 后
UIPasteboard.general.string = ""
但是我们再退出 app (applicationWillResignActive)的时候也这样设置了,导致微信不能分享给朋友,朋友圈等。看来微信有用到和判断。
11.popToRootViewController TabBar 消失
解决1: popToRootViewController(animated: false),没有动画体验会差
解决2: 重写 popToRootViewController 方法
override func popToRootViewController(animated: Bool) -> [UIViewController]? {
guard #available(iOS 14, *) else {
return super.popToRootViewController(animated: animated)
}
viewControllers.forEach({$0.hidesBottomBarWhenPushed = false})
return super.popToRootViewController(animated: animated)
}