SKProduct本地化标题始终为英文

时间:2015-12-27 17:38:37

标签: ios objective-c xcode in-app-purchase skproduct

我正在使用Xcode v7.2和Obj-c。我正在为现有的iOS应用添加不同的语言。主要问题是SKProduct的localizedTitle(iTC上的显示名称)总是以英文显示。 我可以显示价格已正确本地化和格式化。我已经准备好了许多关于SO的类似问题,并尝试过他们的解决方案,但它似乎并没有为我工作(例如:thisthis)。

期望的结果:

  1. 向用户显示3个按钮;每个按钮都有不同的标题和价格。
  2. 动态更改IAP的显示名称&仅在iTC中更新它的价格(因此,每次我想要更改时,我都不必更新代码)。
  3. 由于#2,我无法对按钮上的IAP名称或价格进行硬编码。
  4. 从iTC中拉出本地化标题(iTC上的显示名称)和价格,作为按钮上的文字标签。
  5. 这是我已经设置的内容:

    • 在iTC上创建测试用户并为他们分配不同的商店: iTC test users and stores
    • 在iTC上设置IAP并添加语言和显示名称: iTC IAP list with languages
    • 从iTC获取SKProduct localizedTitle和价格的代码

      [[FirstDrawIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
          if (success) {
              storeProducts = products;
              SKProduct *product = (SKProduct *)storeProducts;
              //Format price
              priceFormatter = [[NSNumberFormatter alloc] init];
              [priceFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
              [priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
      
              //Iterate thru the buttons using tipButton Outlet Collection
              for (int i = 0; i <  [self.tipButton count]; i++) {
                  UIButton *button = [[UIButton alloc] init];
                  button = self.tipButton[i];
                  //product = storeProducts[i];
                  product = products[i];
                  //Set the price locale
                  [priceFormatter setLocale:product.priceLocale];
                  //Localize the button title and append the price
                  NSString *btnTxt = [product.localizedTitle stringByAppendingString:@" "];
                  NSString *price = [priceFormatter stringFromNumber:product.price];
                  NSString *newBtn = [btnTxt stringByAppendingString:price];
                  NSLog(@"\nID: %@, Price: %@, Button: %@",[product localizedTitle], price, btnTxt);
                  //Set button title
                  [button setTitle:newBtn forState:UIControlStateNormal];
      
              }
      
          }
      
    • 创建新的Xcode方案,以便将测试设备语言位置区域设置为所需的国家/地区

    • 在Xcode模拟器上退出App Store(从设置)。在模拟器中运行测试时,我最初会以正确的语言查看我的应用程序,但按钮上的文本是英文的。这是因为我还没有改变App Store的位置。我点击IAP购买按钮,它会提示我登录。
    • 我使用我的测试用户登录该国家/地区。我停止应用程序然后再次运行它。

    结果: 我正确地看到了该国家/地区的IAP价格,但我没有看到该按钮的标题已正确本地化。该按钮的标题仍为英文。这种情况发生在我设置的每种语言中。

    有谁能发现我在这里做错了什么?我是否错误地认为SKProduct.localizedTitle没有返回该语言的iTC显示名称(App Store)?任何帮助将不胜感激,谢谢。

1 个答案:

答案 0 :(得分:3)

基于 In-App Purchase FAQ

  

localizedDescription和localizedTitle返回其语言基于当前iTunes Store而非当前设备语言设置的本地化信息。