从SKTransaction iOS获得便士费用 [英] Get the penny cost from SKTransaction iOS

查看:323
本文介绍了从SKTransaction iOS获得便士费用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试在我的iOS应用中与我的IAP进行一些服务器集成。我发送给服务器的参数需要:transaction_ID,product_ID和pennyCost。



前两个很容易搞清楚,但我找不到成本。我确实有一些NSData用于收据,但我无法弄清楚如何将其变成我可以使用的任何形式。这是我到目前为止的代码。

   - (void)completeTransaction:(SKPaymentTransaction *)transaction {
NSLog(@ completeTransaction ......);

purchaseComplete = 2;

NSString * transaction_key = transaction.transactionIdentifier;
NSString * productID = transaction.payment.productIdentifier;
NSNumber * pennyCost = transaction.payment.product.pennyCost;

NSData * rec = [self receiptForPaymentTransaction:transaction];


}

transaction.payment.product.pennyCost行无效。



任何帮助都会非常棒!谢谢!

解决方案

SKPayment 没有价格,奇怪的是。使用 SKProductRequest 检索产品后,价格在 SKProduct 上定义。



您需要做的是保持对 SKProductRequest 返回的 SKProduct 实例的引用。一旦您向 SKPaymentQueue 提交付款并获得回复,请使用<$ c $的 productId c> SKPayment 查找匹配的 SKProduct



现在,您的应用重启后,您可能会在稍后收到付款交易。在这种情况下,您将需要创建一个新的 SKProductRequest 来获取 SKProduct ,这样您就可以获得价格。 / p>

所有这一切的不好之处在于,您获得的产品价格可能与用户实际收费的价格不同,因为您可能会在时间之间更新产品的定价您收到了付款交易以及您申请产品信息的时间。


Hi I'm trying to do some server integration with my IAPs in my iOS app. The params for what I'm sending to the server require: transaction_ID, product_ID, and pennyCost.

The first two were easy enough to figure out but I can't find the cost. I do have some NSData for the receipt but I can't figure out how to get that into any form I can use. This is my code so far.

- (void)completeTransaction:(SKPaymentTransaction *)transaction {
 NSLog(@"completeTransaction...");

 purchaseComplete = 2;

 NSString *transaction_key = transaction.transactionIdentifier;
 NSString *productID = transaction.payment.productIdentifier;
 NSNumber *pennyCost = transaction.payment.product.pennyCost;

 NSData *rec = [self receiptForPaymentTransaction:transaction];


}

The transaction.payment.product.pennyCost line is invalid.

Any help would be awesome thanks!

解决方案

SKPayment doesn't have a price, oddly enough. The price is defined on the SKProduct after retrieving the product using an SKProductRequest.

What you need to do is keep a reference to the SKProduct instances returned from the SKProductRequest. Once you submit a payment to the SKPaymentQueue and you get back your response, use the productId of the SKPayment to find the matching SKProduct.

Now it's possible that you will receive a payment transaction later, after your app has been restarted. In that case, you will have to make a new SKProductRequest to get the SKProduct so you can get the price.

The bad part about all of this is that the price you get for the product could different from what the user is actually charged since you might update the product's pricing in between the time you received the payment transaction and the time you request the product info.

这篇关于从SKTransaction iOS获得便士费用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆