我需要检测使用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") //
}
答案 0 :(得分:0)
您可以尝试执行此操作,这会为您提供来自蜂窝网络提供商的一些数据,但这仅适用于您自己的设备。不适用于其他用户...
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")"
}