iOS16适配指南之其他细节

  • 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, 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适配指南之其他细节)