Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the alternative solution for paymentWithProductIdentifier?

Tags:

Hi i am using in APP purchase in my project . When i run this project everything works fine, except i am getting a warning message saying that "paymentWithProductIdentifier is deprecated", I gone through the similar questions that are asked in stack overflow but i didn't satisfied. I shown you my coding that i used in the project below

SKPayment *payment=[SKPayment paymentWithProductIdentifier:@"com.mycompany.dmaker.maker1"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];

Can anyone tell me 1)the alternative for this warning. 2)or tell me whether this project approve in appstore if i use this existing code.

like image 963
surendher Avatar asked Jun 01 '12 09:06

surendher


2 Answers

Try using this:

SKProduct *selectedProduct = <#from the products response list#>;
SKPayment *payment = [SKPayment paymentWithProduct:selectedProduct];
[[SKPaymentQueue defaultQueue] addPayment:payment];
like image 137
Nuzhat Zari Avatar answered Sep 22 '22 05:09

Nuzhat Zari


You can replace paymentWithProductIdentifier: with following codes:

// SKPayment *payment = [SKPayment paymentWithProductIdentifier:productId];
// [[SKPaymentQueue defaultQueue] addPayment:payment];
NSSet *productIdentifiers = [NSSet setWithObject:productId];
self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
self.productsRequest.delegate = self; // your wrapper for IAP or AppDelegate or anything
[self.productsRequest start];

while productsRequest is a retain property.

And implement a SKProductsRequestDelegate method:

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    for (SKProduct *product in response.products) {
        SKPayment *payment = [SKPayment paymentWithProduct:product];
        [[SKPaymentQueue defaultQueue] addPayment:payment];
    }
    self.productsRequest = nil;
}
like image 29
hiroshi Avatar answered Sep 20 '22 05:09

hiroshi