RegionCode 将在 iOS 16 中弃用

Ash*_*iya 2 xcode ios swift ios16

从 iOS 16 开始,regionCode尝试regionCode从当前区域设置访问时不再适用。喜欢这个代码

let locale = Locale.current
locale.regionCode
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Ash*_*iya 6

iOS 16及更早版本的解决方案

    let locale = Locale.current
    var countryCode = ""
    if #available(iOS 16, *) {
        if let value = locale.region?.identifier {
            countryCode = value
        }
    } else {
        if let value = locale.regionCode {
            countryCode = value
        }
    }
    print(countryCode)
Run Code Online (Sandbox Code Playgroud)