alamofire验证证书
故障现象:xcode log日志显示如下错误,并且相关请求出错1
2
3
4
5
6
7
8
92019-07-17 11:38:19.396278+0800 Homecare[10181:3941027] CredStore - performQuery - Error copying matching creds. Error=-25300, query={
class = inet;
"m_Limit" = "m_LimitAll";
ptcl = htps;
"r_Attributes" = 1;
sdmn = Users;
srvr = "cloud.demo.cn";
sync = syna;
}
原因:ios系统验证网站的证书出错 (ps:不过不知道什么原因,这个故障是偶现的^)
处理:无条件信任我们自己的服务器,不需要进行证书校验1
2
3
4
5
6
7
8
9
10
11
12init() {
//关闭认证
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = Alamofire.SessionManager.defaultHTTPHeaders
configuration.urlCredentialStorage = nil
let policies: [String: ServerTrustPolicy] = [
"cloud.demo.cn": .disableEvaluation
]
super.init(configuration: configuration,serverTrustPolicyManager: ServerTrustPolicyManager(policies: policies))
}
手动添加的自动布局代码不生效
1 | let subView = UIView() |
故障现象:运行的时候发现subview自动生成了midx=0,midy=0,height=0,width=0的约束代码
解决方案:关掉自动生成约束代码的功能1
2
3let subView = UIView()
subview.translatesAutoresizingMaskIntoConstraints = false
.......
ATS报错
故障现象:
app发送https://cloud.fanmiot.cn/rest/things请求,结果返回ats报错,日志如下:1
2
3
42019-07-23 09:26:33.044872+0800 Homecare[5571:122357] Task <5547B0FE-DA52-400E-AF8E-D97453C9F2B0>.<1> finished with error - code: -1022
2019-07-23 09:26:33.046236+0800 Homecare[5571:122356] Task <5547B0FE-DA52-400E-AF8E-D97453C9F2B0>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLStringKey=http://undefined/rest/things, NSErrorFailingURLKey=http://undefined/rest/things, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <5547B0FE-DA52-400E-AF8E-D97453C9F2B0>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <5547B0FE-DA52-400E-AF8E-D97453C9F2B0>.<1>, NSUnderlyingError=0x600003f18b10 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}} [-1022]
故障原因:
https://cloud.fanmiot.cn/rest/things不可达时,服务器端自动跳转到了http://undefined/rest/things页面……
视图不显示
故障现象:1
2
3
4
5
6
7
8class aViewController {
override func viewDidLoad() {
super.viewDidLoad()
let vc = bTabelViewController()
view.addsubView(vc.view)
}
}
问题原因:
vc是函数内的局部变量,函数执行结束就被释放掉了;bTabelViewController的cell是根据数据动态生成的;而这些数据也随着vc的释放而消失了……
所以需要将let vc = bTabelViewController() 移到函数外
在地图上画线,产生偏移
问题代码:1
2
3
4let startPoint = mapView.convert(start.coordinate, toPointTo: mapView)
let endPoint = mapView.convert(end.coordinate, toPointTo: mapView)
......
self.view.layer.addSublayer(lineLayer)
问题分析:
将经纬度转成view坐标是以mapview为参考,实际作用于view;所以当view和mapview不重合时就出现问题了,修正后代码:1
2
3
4let startPoint = mapView.convert(start.coordinate, toPointTo: view)
let endPoint = mapView.convert(end.coordinate, toPointTo: view)
......
self.view.layer.addSublayer(lineLayer)