【问题标题】:How to detect country and state in iOS?如何在 iOS 中检测国家和州?
【发布时间】:2019-07-15 20:51:18
【问题描述】:

我需要使用 Swift 5 检测设备在哪个国家和州,并且没有 Internet 连接。

reverseGeocodeLocation:

func getCityInLocation(from 
location:CLLocation,completion:@escaping(_city:String?, _ error:Error?) ->()) {
    CLGeocoder().reverseGeocodeLocation(location) { placemarks, error in
        completion(placemarks ?.first ?.locality, error)
    }
}

let location = CLLocation(latitude:19.339248,longitude:-99.191345)

getCityInLocation(from:location) { city, error in
    guard let city = city, error == nil else{
        return
    }

    print(city + "????Line 705")  //
}

【问题讨论】:

    标签: ios swift core-location reverse-geocoding


    【解决方案1】:

    您可以试试这个,它会向您提供一些来自蜂窝网络提供商的数据,但这仅适用于您自己的设备。不适用于其他用户...

    let networkInfo = CTTelephonyNetworkInfo()
    if let provider = networkInfo.serviceSubscriberCellularProviders?.first?.value {
                    supportText += "\n Carrier: \(provider.carrierName ?? "None")"
                    supportText += "\n ISO Location: \(provider.isoCountryCode ?? "None")"
                    supportText += "\n Mobile Location: \(provider.mobileCountryCode ?? "None")"
    }
    

    【讨论】:

    • 感谢您的回答。我真的很想检测我的设备的配置。设置 > 通用 > 数据和时间 > 时区(选择) 如何根据时区获取所选城市的名称?
    猜你喜欢
    • 2015-04-14
    • 2014-02-24
    • 2013-11-13
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    相关资源
    最近更新 更多