How to force language in which reverse geocoding data on iOS is received?

前端 未结 4 787
栀梦
栀梦 2021-01-14 06:04

When i call

geocoder reverseGeocodeLocation:currentLoc completionHandler:

i get all the data (city, county, ...) in a language according t

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-14 06:34

    For future readers, the accepted answer is not true (at least not any more).

    UserDefaults.standard.set(["en"], forKey: "AppleLanguages")
    gc.reverseGeocodeLocation(loc) {
        print($0 ?? $1!)
    
        UserDefaults.standard.removeObject(forKey: "AppleLanguages")
        print(UserDefaults.standard.object(forKey: "AppleLanguages") as! [String])
    }
    

    Calling removeObject(forKey:) is important since you want to reset the returned value in UserDefaults to the system settings. Some answers make you hold the original value from calling UserDefaults.standard.object(forKey: "AppleLanguages") and set it after getting the address, but this will stop your UserDefaults from being in sync with the global Language Preferences in iOS "Settings" app.

提交回复
热议问题