我正在使用 Xcode v7.2 和 Obj-c。我正在向现有的 iOS 应用程序添加不同的语言。主要问题是 SKProduct 本地化标题(iTC 上的显示名称)总是以英文返回。 我可以显示正确本地化和格式化的价格。我已经准备好关于 SO 的许多类似问题并尝试了他们的解决方案,但它似乎对我不起作用(例如:this和this)。
期望的结果:
- 向用户显示 3 个按钮;每个按钮都有不同的标题和价格。
- 通过仅在 iTC 中更新它来动态更改 IAP 的显示名称和价格(因此我不必每次想要更改时都更新代码)。
- 由于 #2,我无法在按钮上硬编码 IAP 名称或价格。
- 从 iTC 中提取本地化标题(iTC 上的显示名称)和价格,用作按钮上的文本标签。
这是我已经设置的内容:
- 在 iTC 上创建测试用户并为他们分配不同的商店:
- 在 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 方案,以便将测试设备Language、Location和Region设置为所需的国家/地区
- 在 Xcode 模拟器上退出 App Store(从Settings)。在模拟器中运行测试时,我最初会以正确的语言看到我的应用程序,但按钮上的文本是英文的。这是因为我还没有更改 App Store 的位置。我点击 IAP 购买按钮,它会提示我登录。
- 我使用该国家/地区的测试用户登录。我停止应用程序然后再次运行它。
结果: 我正确地看到了该国家/地区的 IAP 价格,但我没有看到正确本地化的按钮标题。按钮的标题仍然是英文。我设置的每种语言都会发生这种情况。
谁能发现我在这里做错了什么?我是否错误地假设 SKProduct.localizedTitle 不返回该语言的 iTC 显示名称(App Store)?任何帮助将不胜感激,谢谢。