xcode PaymentWithProductIdentifier 在特定于应用程序购买中已弃用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12415044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
paymentWithProductIdentifier deprecated in app purchase specific
提问by Alex G
Possible Duplicate:
what is the alternative solution for paymentWithProductIdentifier?
Hello I am trying to set up in app purchases for ios 5 and newly ios 6. I am being told that my "paymentWithProductIdentifier is deprecated" and I was wondering if someone could tell me how to modify my code, I am a little confused.
您好,我正在尝试为 ios 5 和新的 ios 6 设置应用程序购买。有人告诉我我的“paymentWithProductIdentifier 已弃用”,我想知道是否有人可以告诉我如何修改我的代码,我有点困惑。
SKProduct *selectedProduct = <#from the products response list#>;
SKPayment *payment = [SKPayment paymentWithProduct:selectedProduct];
[[SKPaymentQueue defaultQueue] addPayment:payment];
I have seen people suggest the following but I am not sure from my code what "the products response list would be". I thought it would be but its not.
我看到有人提出以下建议,但我从我的代码中不确定“产品响应列表是什么”。我以为会是,但不是。
[response.products];
Here is my code for the method, if anyone can tell me what to change it would be appreciated thanks!
这是我的方法代码,如果有人能告诉我要更改什么,将不胜感激,谢谢!
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
SKProduct *validProduct = nil;
int count = [response.products count];
NSLog (@"count for in app purchases is %d", count);
if (count>0) {
validProduct = [response.products objectAtIndex:0];
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"appUpdate1"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment]; // <-- KA CHING!
NSLog (@"payment proccessed I think");
}
}
回答by rdelmar
It looks like you're assuming that there is only one product, which you set to validProduct. You should be able to use
看起来您假设只有一种产品,您将其设置为 validProduct。你应该可以使用
SKPayment *payment = [SKPayment paymentWithProduct:validProduct]
The productIdentifier is a property of the SKProduct, so this method creates the new payment object with the identifier it gets from the SKProduct.
productIdentifier 是 SKProduct 的一个属性,因此此方法使用从 SKProduct 获取的标识符创建新的支付对象。