我有一个应用程序内购买商品,价格为1.99英镑。我使用弹出窗口显示此价格,但是,当设备未连接到互联网时,它无法获取我的IAP价格,因此显示为空白。

我的IAP价格始终为1.99英镑。设备未连接到互联网时,如何在其他国家/地区显示此IAP层?

这是我目前如何获得IAP价格的方法:

_products = nil;
        [[AppIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
            if (success) {
                _products = products;

                SKProduct * product = _products[0];

                [[AppIAPHelper sharedInstance] productPurchased:product.productIdentifier];

                NSNumberFormatter *_priceFormatter = [[NSNumberFormatter alloc] init];
                [_priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
                [_priceFormatter setLocale:product.priceLocale];
                priceString = [_priceFormatter stringFromNumber:product.price];

                NSLog(@"Price string: %@",priceString);
            }
        }];


我试图测试priceString.count <= 0(因此设备未连接到互联网),然后执行:

NSDecimalNumber *amount = [NSDecimalNumber decimalNumberWithString:@"1.99"];
NSNumberFormatter *currencyFormat = [[NSNumberFormatter alloc] init];
NSLocale *locale = [NSLocale currentLocale];
[currencyFormat setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormat setLocale:locale];
NSLog(@"AmountSo with symbol: %@", [currencyFormat stringFromNumber:amount]);//Eg: $50.00
NSLog(@"Current Locale : %@", [locale localeIdentifier]);//Eg: en_US


但是,这只会将本地货币符号添加到amount

问题是,我需要显示正确的价格等级。例如,转换为GBP的USD 1.99为1.27。但是,IAP等级为1.99美元和1.49英镑。

因此,基本上-我如何在不要求SKProduct的价格的情况下(如果用户未连接到互联网)显示用户本地货币的App Store IAP价格等级?谢谢。

最佳答案

您可以创建一个属性列表(plist),静态NSDictionary或其他一些包含映射到国家/地区代码的当前价格层的关系表。如果没有网络连接可用,请抓住the current locale country并使用它来查找价格层和本地货币符号。

但是,问题是:既然没有网络连接就无法进行应用内购买,为什么还要担心呢?只是发出一条通知,指出网络连接不可用?

如果您希望它更加健壮,还可以使用一个选项,将其设置为使用一种策略进行缓存,该策略将在网络可用时刷新它,否则使用缓存的副本。使用Reachability这样的东西将起作用,尽管公认的是,这是针对NSURLRequest而不是SKProduct请求的。

Reachability *reachability = [Reachability reachabilityForInternetConnection];
NetworkStatus netStatus = [reachability currentReachabilityStatus];
if (netStatus == ReachableViaWiFi)
    [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
else
    [request setCachePolicy:NSURLRequestReturnCacheDataElseLoad];

关于ios - 设备无法检索SKProduct价格时显示IAP价格,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26985479/

10-12 14:43
查看更多