支持Xcode10和适配iPhone XS Max、iPhone XR

2018 年 10 月 4 日 CocoaChina

本公众号内容均为本号转发,已尽可能注明出处。因未能核实来源或转发内容图片有权利瑕疵的,请及时联系本号,本号会第一时间进行修改或删除。 QQ : 3442093904 




目前我们项目已做了Xcode10(swift4.0)和新机型的适配,总结一下遇到的问题和修改的内容,希望帮助到其他人,如果您有不同的看法或遗漏,欢迎指出!


1.第三方库编译报错


如果项目里用到了Mixpanel-swift和SwiftLint,这两个在Xcode10上会报错,目前作者已提交新版本分别是2.4.5和0.27.0,更新后即可解决报错。


2.library not found for - lstdc++.6.0.9


pod工程编译通过后会进行主工程的编译,如果依赖了libstdc++.tbd和libstdc++.6.0.9.tbd,就会报这个error,原因是苹果在XCode10和iOS12中移除了libstdc++这个库,由libc++这个库取而代之,苹果的解释是libstdc++已经标记为废弃有5年了,建议大家使用经过了llvm优化过并且全面支持C++11的libc++库。


临时的解决方法就是把libstdc++.6.0.9.tbd这个文件导入到Xcode10中,分别放到以下目录 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/   和 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/  这时编译可以通过。


但这只是临时的解决方案,如果你自己的业务模块使用了libstdc++,那么就把模块代码重新调整为依赖libc++,然后重新检查是否存在问题,重新编译。如果你引用的第三方厂商提供的sdk中依赖了libstdc++,那么抓紧联系厂商,要求版本升级。


3.Enum case '...' not found in type '...'


解决好上面两个报错,编译程序时还会显示这个error,具体场景如下:


PosVisitQuestionType: String {
    case text
    case textArea = "text_area"
    case dropDownList = "drop_down_list"
    case radioButton = "radio_button"
}
let type: PosVisitQuestionType!
...
switch type {
case .text, .textArea:
    errorText = NSLocalizedString("Please enter the following options", comment: "")
case .dropDownList, .radioButton:
    errorText = NSLocalizedString("Click the right button to get current location", comment: "")
default:
    break
}


Xcode10建议每个case 情况下加“?”



原因可能是 type是可选的,所以每个case情况要与type类型保持一致,所以提示加 “?”,可能是Xcode10编译器更新的原因。


修改的方法是如果确定type会被赋值,那在定义的时候就把“!”去掉,如果不确定type是否有值就按照Xcode提示修改。


4.适配iPhone XS Max、iPhone XR


我们项目在获取机型等信息用的是DeviceKit这个第三方库,所以也需要更新一下才能获取到新机型的信息,最新版是1.8.1。在最新版有这样一个变量


/// All Face ID Capable Devices
    static public var allFaceIDCapableDevices: [Device] {
      return [.iPhoneX, .iPhoneXs, .iPhoneXsMax, .iPhoneXr]
    }


由于iPhone X、iPhone XS、iPhone XS Max、iPhone XR这些机型的navigationBar高度以及tabBar高度都一致,所以可以用allFaceIDCapableDevices是否包含当前设备,来判断当前设备是否有“齐刘海”。


示例:


static let faceIDDeviceArray = Device.allFaceIDCapableDevices

static let navigationHeight: CGFloat = {
        if faceIDDeviceArray.contains(currentDevice) {
            return faceIDDeviceNavHeight
        } else {
            return ordinaryDeviceNavHeight
        }
    }()


同时DeviceKit中也提供这样一个方法,运行模拟器的时候调用,也会返回真实的设备名称


/// Get the real device from a device. If the device is a an iPhone8Plus simulator this function returns .iPhone8Plus (the real device).
    /// If the parameter is a real device, this function returns just that passed parameter.
    ///
    /// - parameter device: A device.
    ///
    /// - returns: the underlying device If the `device` is a `simulator`,
    /// otherwise return the `device`.
    public static func realDevice(from device: DeviceKit.Device) -> DeviceKit.Device


示例:


static let currentDevice = Device.realDevice(from: Device())
if currentDevice == .iPhoneX {}
// 取代以下写法
if Device(== .iPhoneX || Device() == .simulator(.iPhoneX) {}


最后别忘了再切两张启动图,因为iPhone XS和尺寸和iPhone X是一样的,所以iPhone XS可以忽略


iPhone XR:828px x 1792px

iPhone XS Max: 1242px x 2688px


参考链接


谢谢各位,欢迎指教!

作者:Mister_H

链接:https://www.jianshu.com/p/24920e577e07


更多推荐


登录查看更多
0

相关内容

苹果公司出品的主要用于 Mac 以及 iOS 开发的 IDE。
专知会员服务
42+阅读 · 2020年7月7日
【实用书】学习用Python编写代码进行数据分析,103页pdf
专知会员服务
190+阅读 · 2020年6月29日
专知会员服务
28+阅读 · 2020年5月20日
【强化学习资源集合】Awesome Reinforcement Learning
专知会员服务
93+阅读 · 2019年12月23日
Stabilizing Transformers for Reinforcement Learning
专知会员服务
57+阅读 · 2019年10月17日
MIT新书《强化学习与最优控制》
专知会员服务
270+阅读 · 2019年10月9日
已删除
AI掘金志
7+阅读 · 2019年7月8日
Pupy – 全平台远程控制工具
黑白之道
43+阅读 · 2019年4月26日
使用 C# 和 Blazor 进行全栈开发
DotNet
6+阅读 · 2019年4月15日
支持多标签页的Windows终端:Fluent 终端
Python程序员
7+阅读 · 2019年4月15日
C# 10分钟完成百度人脸识别
DotNet
3+阅读 · 2019年2月17日
超级!超级!超级好用的视频标注工具
极市平台
8+阅读 · 2018年12月27日
Android P正式发布,你需要尽快做适配了
前端之巅
3+阅读 · 2018年8月7日
使用Keras和LSTM生成说唱歌词
论智
5+阅读 · 2018年5月22日
AliCoCo: Alibaba E-commerce Cognitive Concept Net
Arxiv
13+阅读 · 2020年3月30日
Arxiv
6+阅读 · 2019年4月8日
Learning Implicit Fields for Generative Shape Modeling
Arxiv
10+阅读 · 2018年12月6日
Deep Reinforcement Learning: An Overview
Arxiv
17+阅读 · 2018年11月26日
Feature Selection Library (MATLAB Toolbox)
Arxiv
7+阅读 · 2018年8月6日
Arxiv
5+阅读 · 2018年5月1日
VIP会员
相关VIP内容
专知会员服务
42+阅读 · 2020年7月7日
【实用书】学习用Python编写代码进行数据分析,103页pdf
专知会员服务
190+阅读 · 2020年6月29日
专知会员服务
28+阅读 · 2020年5月20日
【强化学习资源集合】Awesome Reinforcement Learning
专知会员服务
93+阅读 · 2019年12月23日
Stabilizing Transformers for Reinforcement Learning
专知会员服务
57+阅读 · 2019年10月17日
MIT新书《强化学习与最优控制》
专知会员服务
270+阅读 · 2019年10月9日
相关资讯
已删除
AI掘金志
7+阅读 · 2019年7月8日
Pupy – 全平台远程控制工具
黑白之道
43+阅读 · 2019年4月26日
使用 C# 和 Blazor 进行全栈开发
DotNet
6+阅读 · 2019年4月15日
支持多标签页的Windows终端:Fluent 终端
Python程序员
7+阅读 · 2019年4月15日
C# 10分钟完成百度人脸识别
DotNet
3+阅读 · 2019年2月17日
超级!超级!超级好用的视频标注工具
极市平台
8+阅读 · 2018年12月27日
Android P正式发布,你需要尽快做适配了
前端之巅
3+阅读 · 2018年8月7日
使用Keras和LSTM生成说唱歌词
论智
5+阅读 · 2018年5月22日
相关论文
AliCoCo: Alibaba E-commerce Cognitive Concept Net
Arxiv
13+阅读 · 2020年3月30日
Arxiv
6+阅读 · 2019年4月8日
Learning Implicit Fields for Generative Shape Modeling
Arxiv
10+阅读 · 2018年12月6日
Deep Reinforcement Learning: An Overview
Arxiv
17+阅读 · 2018年11月26日
Feature Selection Library (MATLAB Toolbox)
Arxiv
7+阅读 · 2018年8月6日
Arxiv
5+阅读 · 2018年5月1日
Top
微信扫码咨询专知VIP会员