【问题标题】:set a constant language to CLPlacemark instance class将常量语言设置为 CLPlacemark 实例类
【发布时间】:2021-02-03 13:23:16
【问题描述】:

我到处寻找,但没有找到这个答案。

我正在构建一个使用用户位置(纬度 + 经度)的 iOS 应用 创建一个 CLPlacemark,并将街道 + 国家发送到服务器并根据此位置返回响应。

现在服务器只能获取希伯来语值,CLPlacemark值是根据用户的操作系统而变化的。

我可以为 CLPlacemark 类实例设置 const 语言吗? 我希望无论用户的操作系统如何,CLPlacemark 都会返回希伯来语

这是我的代码:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    geoCoder = [[CLGeocoder alloc]init];
    [self.geoCoder reverseGeocodeLocation:locationManager.location completionHandler:
     ^(NSArray *placemarks, NSError *error) {

         CLPlacemark *placemark = [placemarks objectAtIndex:0];
         placemark.

         self.countryTextBox.text =[placemark.addressDictionary valueForKey:@"Country"];
         self.citiTextBox.text =[placemark.addressDictionary valueForKey:@"City"];
         self.streetTextBox.text =[placemark.addressDictionary valueForKey:@"Street"];
         self.zipCodLbl.text =[placemark.addressDictionary valueForKey:@"ZIP"];


         //NSLog(@"%@",placemark.addressDictionary);
         NSLog(@"%@",[placemark.addressDictionary valueForKey:@"Country"]);
         NSLog(@"%@",[placemark.addressDictionary valueForKey:@"City"]);
         NSLog(@"%@",[placemark.addressDictionary valueForKey:@"Street"]);
         NSLog(@"%@",[placemark.addressDictionary valueForKey:@"ZIP"]);

         [locationManager stopUpdatingLocation];
         [self.animationBar stopAnimating];



             }];

}

非常感谢。

伊丹。

【问题讨论】:

    标签: iphone ios objective-c localization hebrew


    【解决方案1】:

    经过几天的苦苦搜索,我终于解决了。

    在视图中确实加载了这行代码:

    [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"he"] forKey:@"AppleLanguages"];
    

    如果这对某人有帮助 - 太好了!

    【讨论】:

    • 我很高兴我帮助了另一个以色列开发者 :) 享受 (tavala!:))
    • 你也可以在main.m文件中添加这一行到return UIApplicationMain之前
    • 这会破坏用户的系统范围偏好。不保存设置并在执行此操作后立即恢复它们是非常非常糟糕的做法。
    【解决方案2】:

    弄乱用户的系统偏好是不好的做法! 你应该改用:

    NSLocale *yourLocal = [[NSLocale alloc] initWithLocaleIdentifier:@"de"];
    [geoCoder reverseGeocodeLocation: preferredLocale:yourLocal completionHandler:
         ^(NSArray *placemarks, NSError *error) {
    
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-28
      • 2017-04-10
      • 1970-01-01
      相关资源
      最近更新 更多