2017-06-06 5 views
1

私はローカリゼーションとcllocationManager言語は変更されましたが、CLLocationManagerは影響を受けませんでしたか?

ローカリゼーションとは全く行われていない以前の言語が付属していた言語うまく機能し、すべてのものは、単に国や都市の名前を変更した場合、唯一の方法は、アプリを閉じて、それを開くことですを使用していますもう一度新しい言語を使いましょう! アプリを終了せずに国と都市を変更するには?

ローカライズコード

static func setLanguage(lang:String) -> Void { 
    UserDefaults.standard.removeObject(forKey: "AppleLanguages") 
    UserDefaults.standard.set([lang], forKey: "AppleLanguages") 
    UserDefaults.standard.synchronize() 

    Bundle.setLanguage(lang) 
} 

CLLocationManagerコード

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
    locValue = manager.location!.coordinate 
    print("locations = \(locValue.latitude) \(locValue.longitude)") 


    let geoCoder = CLGeocoder() 
    let location = CLLocation(latitude: locValue.latitude, longitude: locValue.longitude) 

    geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in 

     // Place details 
     var placeMark: CLPlacemark! 
     placeMark = placemarks?[0] 

     if placeMark != nil{ 
      // City 
      if let city = placeMark.addressDictionary!["State"] as? NSString { 

       self.locCity = city as String 
      } 



      // Country 
      if let country = placeMark.addressDictionary!["Country"] as? NSString { 

       self.locCountry = "\(country)," as String 
      } 

      self.countryLocation.text = "\(self.locCountry) \(self.locCity)" 
      self.locationManager.stopUpdatingLocation() 
     } 

    }) 
} 

答えて

1

あなたがそのような変化を検出するNSLocale.currentLocaleDidChangeNotificationにオブザーバを追加する必要があります。このような

何か:何かがNSLocaleに変更されます一度

NotificationCenter.default.addObserver(self, selector: #selector(MyClass.languageDidChange), 
               name: NSLocale.currentLocaleDidChangeNotification, object: nil) 

そしてlanguageDidChangeメソッドが呼び出されます。

これが役に立ちます。

+0

私は同じことを試していますが、問題は言語の火の変化ではありません問題はCLLocationManagerが言語のパラメータを取らず、アプリケーションを再起動する必要があります – MOMMH

+0

@MOMMHは、 CLLocationManager'? –

+0

いいえ、CLLocationManager、サンプルコード、またはリンクを再初期化する方法はわかりません。 – MOMMH

関連する問題