what is the alternative solution for paymentWithProductIdentifier? what is the alternative solution for paymentWithProductIdentifier? xcode xcode

what is the alternative solution for paymentWithProductIdentifier?


Try using this:

SKProduct *selectedProduct = <#from the products response list#>;SKPayment *payment = [SKPayment paymentWithProduct:selectedProduct];[[SKPaymentQueue defaultQueue] addPayment:payment];


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;}


You have 3 options:

  • suppress this warning with preprocessor definition:

    #pragma clang diagnostic push#pragma clang diagnostic ignored "-Wdeprecated-declarations"SKPayment *payment=[SKPayment paymentWithProductIdentifier:@"com.mycompany.dmaker.maker1"];#pragma clang diagnostic pop[[SKPaymentQueue defaultQueue] addPayment:payment];
  • create SKMutablePayment instead of SKPayment:

    SKMutablePayment *payment = [[SKMutablePayment alloc] init];payment.productIdentifier = @"com.mycompany.dmaker.maker1";payment.quantity = 1;[[SKPaymentQueue defaultQueue] addPayment:payment];
  • use paymentWithProduct: convenience initializer:

    SKPayment *payment = [SKPayment paymentWithProduct:<# product that you received in productsRequest:didReceiveResponse: #>];[[SKPaymentQueue defaultQueue] addPayment:payment];