what is the alternative solution for paymentWithProductIdentifier?

前端 未结 4 1161
醉酒成梦
醉酒成梦 2020-12-15 18:34

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

4条回答
  •  抹茶落季
    2020-12-15 18:52

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

提交回复
热议问题