what is the alternative solution for paymentWithProductIdentifier?

前端 未结 4 1168
醉酒成梦
醉酒成梦 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条回答
  •  萌比男神i
    2020-12-15 19:02

    You could use the following code instead, it does have a little extra that you may already have, but just to make sure

    #define kInAppPurchaseId "(your product ID here)"
    
    - (void)makePurchase{
    //call this when you would like to begin the purchase
    //like when the user taps the "purchase" button
    NSLog(@"User requests to make purchase");
    
    if([SKPaymentQueue canMakePayments]){
        NSLog(@"User can make payments");
    
        SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:kInAppPurchaseId]];
        productsRequest.delegate = self;
        [productsRequest start];
    
    }
    else{
        //the user is not allowed to make payments
        NSLog(@"User cannot make payments due to parental controls");
    }
    }
    
    - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
    SKProduct *validProduct = nil;
    int count = [response.products count];
    if(count > 0){
        validProduct = [response.products objectAtIndex:0];
        NSLog(@"Products Available!");
        [self purchase:validProduct];
    }
    else if(!validProduct){
        NSLog(@"No products available");
    }
    }
    
    - (IBAction)purchase:(SKProduct *)product{
    SKPayment *payment = [SKPayment paymentWithProduct:product];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
    }
    

    I use this code in one off my applications, so it should work.

提交回复
热议问题