iOS16适配指南之其他细节

作者: YungFan | 来源:发表于2022-08-30 14:46 被阅读0次
    • URLSession 建议通过连接迁移来优化网络切换场景下的 TCP 连接重建,降低网络的延迟。
    import UIKit
    
    class ViewController: UIViewController {
        lazy var session: URLSession = {
            let configuration = URLSessionConfiguration.default
            // MultipathServiceType是一个枚举类型,App可以采用不同的策略来利用这些网络通道
            configuration.multipathServiceType = .handover
            let session = URLSession(configuration: configuration)
            return session
        }()
    
        override func viewDidLoad() {
            super.viewDidLoad()
        }
    }
    
    • 打开系统通知设置界面的 URL Scheme 从
      UIApplicationOpenNotificationSettingsURLString替换为openNotificationSettingsURLString
    import UIKit
    
    class ViewController: UIViewController {
        override func viewDidLoad() {
            super.viewDidLoad()
        }
    
        override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
            // 新的通知设置URL Scheme
            let urlString = UIApplication.openNotificationSettingsURLString
            if let url = URL(string: urlString), UIApplication.shared.canOpenURL(url) {
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            }
        }
    }
    
    • UIScreen.main即将被废弃,建议使用(UIApplication.shared.connectedScenes.first as? UIWindowScene)?.screen
    import UIKit
    
    class ViewController: UIViewController {
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // 新的获取UIScreen尺寸的方法
            if let screen = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.screen {
                print(screen)
            }
        }
    }
    

    相关文章

      网友评论

        本文标题:iOS16适配指南之其他细节

        本文链接:https://www.haomeiwen.com/subject/gzvlnrtx.html