8

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

期望的结果:

  1. 向用户显示 3 个按钮;每个按钮都有不同的标题和价格。
  2. 通过仅在 iTC 中更新它来动态更改 IAP 的显示名称和价格(因此我不必每次想要更改时都更新代码)。
  3. 由于 #2,我无法在按钮上硬编码 IAP 名称或价格。
  4. 从 iTC 中提取本地化标题(iTC 上的显示名称)和价格,用作按钮上的文本标签。

这是我已经设置的内容:

  • 在 iTC 上创建测试用户并为他们分配不同的商店: iTC 测试用户和商店
  • 在 iTC 上设置 IAP 并添加语言和显示名称: 带有语言的 iTC IAP 列表
  • 从 iTC 获取 SKProduct 本地化标题和价格的代码

    [[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 方案,以便将测试设备LanguageLocationRegion设置为所需的国家/地区

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

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

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

4

1 回答 1

5

基于 应用内购买常见问题解答

本地化描述和本地化标题返回本地化信息,其语言基于当前 iTunes Store 而不是当前设备语言设置。

于 2018-01-15T20:30:16.183 回答