0

I need to detect in which country and state the device is with Swift 5 and without an Internet connection.

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")  //
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
D.Sanxhez
  • 137
  • 8

1 Answers1

0

You can try this, which will gibe you some data from the cellular provider, but this is just for your own device. Not for other users...

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")"
}
arvidurs
  • 2,853
  • 4
  • 25
  • 36
  • Thanks for answering. I reallly want to detected what configuration my device. Settings > General > Data & Time > Time Zone (Selection) How to get the name of the selected city based on the time zone? – D.Sanxhez Jul 16 '19 at 14:59
  • https://stackoverflow.com/questions/27053135/how-to-get-a-users-time-zone – arvidurs Jul 17 '19 at 03:34