如何在ios 9.0的swift 4中本地化城市语言?

如何在ios 9.0的swift 4中本地化城市语言?,ios,swift4,cllocationmanager,cllocation,nslocalizedstring,Ios,Swift4,Cllocationmanager,Cllocation,Nslocalizedstring,我在应用程序中使用了location,它将在应用程序中获取纬度和经度,然后可以给我用户所在城市的名称 这个名字是英文的,但我想把它转换成波斯语 我发现了这个方法,但它在iOS 11中可以工作,但我是在iOS 9上开发的。如何才能用波斯语打印当前城市? 这是我的密码 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { if firstUpdate

我在应用程序中使用了location,它将在应用程序中获取纬度和经度,然后可以给我用户所在城市的名称 这个名字是英文的,但我想把它转换成波斯语 我发现了这个方法,但它在iOS 11中可以工作,但我是在iOS 9上开发的。如何才能用波斯语打印当前城市? 这是我的密码

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    if firstUpdate {
        if let _latitude = locations.first?.coordinate.latitude {
            if let _longitude = locations.first?.coordinate.longitude {
                firstUpdate = false
                self.locationManager.stopUpdatingLocation()
                self.carregaDadosLocal(latitude: _latitude, longitude: _longitude)
                let location = CLLocation(latitude: _latitude, longitude: _longitude)
                if #available(iOS 11.0, *) {
                    CLGeocoder().reverseGeocodeLocation(location, preferredLocale: Locale(identifier: "fa_IR")) { (local, error) in

                        if (local?[0]) != nil {

                            print(local?[0].thoroughfare!)
                            print(local?[0].locality)
                            print(local?[0].location)
                            print(local?[0].subLocality)

                        }
                    }
                } else {
                    // Fallback on earlier versions
                }
            }
        }
    }
}

在iOS 9上,您可以临时覆盖应用程序的语言:

func completionHandler(_ placemarks: [CLPlacemark]?, _ error: Error?) {
    if let place = placemarks?.first {
        print(place.thoroughfare!)
        print(place.locality)
        print(place.location)
        print(place.subLocality)
    }
}

let location = CLLocation(latitude: 48.858370, longitude: 2.294481)
if #available(iOS 11.0, *) {
    CLGeocoder().reverseGeocodeLocation(location, preferredLocale: Locale(identifier: "fa_IR"), completionHandler: completionHandler)
} else {
    UserDefaults.standard.set(["fa_IR"], forKey: "AppleLanguages")
    CLGeocoder().reverseGeocodeLocation(location) { placemarks, error in
        // Remove the language override
        UserDefaults.standard.removeObject(forKey: "AppleLanguages")
        completionHandler(placemarks, error)
    }
}
问题是,不管用户设置如何,你的应用程序都会在短时间内变成波斯语。任何依赖于区域设置的内容(如
NSLocalizedString
NumberFormatter
)都将受到影响