1

正如标题所示,我需要获取应用内产品价格,但对于美国应用商店,完全忽略用户当前的区域设置和设置。

换句话说,
即使本地用户设置为俄罗斯/法国/其他,也可以获取产品的美元价格。

谢谢

4

1 回答 1

2

您需要的内容将在 SKProductsRequest 中提供。如果您使用 SKRequestDelegate 协议实现一个对象,您可以获得价格。如果您愿意,可以选择将语言环境硬编码为美国。

要设置请求:

NSSet* identifiers = [NSSet setWithObjects:inAppIdentiferOne, inAppIdentifierTwo, nil];

SKProductsRequest* productRequest= [[SKProductsRequest alloc] initWithProductIdentifiers:identifiers];
productRequest.delegate = self;
[productRequest start];

处理响应:

-(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
     for(int i=0; i<response.products.count; i++)
     {
         SKProduct* instance = [response.products objectAtIndex:i];

         NSLog(@"IAP Desc: %@. Title: %@.", instance.localizedDescription, instance.localizedTitle);

         // This is where you can hardcode the US locale by setting a NSLocale type
         // I'm not 100% sure on how to set the NSLocale correctly, so currently this line sets localization
         NSLocale* locale = instance.priceLocale;

         NSNumberFormatter* fmtr = [[NSNumberFormatter alloc] init];
         [fmtr setNumberStyle:NSNumberFormatterCurrencyStyle];
         [fmtr setLocale:locale];

         if([instance.productIdentifier isEqualToString:inAppIdentiferOne]) 
         {
             NSString* localizedCostString = [fmtr stringFromNumber:(instance.price)];
             NSString* productIdentifier = instance.productIdentifier;
         }
         else if([instance.productIdentifier isEqualToString:inAppIdentiferTwo]) 
         {
             NSString* localizedCostString = [fmtr stringFromNumber:(instance.price)];
             NSString* productIdentifier = instance.productIdentifier;
         }
     }
 }

还有一个可选函数来处理检索这些您可能想要处理的标识符的失败。

于 2013-08-14T09:37:40.947 回答