0

I am trying to add In-App-Purchare in application. With the help of some YouTube videos and other tutorials I have performed some code in my project. But there is no response on tapping the button. Here is my code which i have integrated in my project. Please help me to complete this task

-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {

NSUInteger count = [response.products count];
if(count > 0){
    _product = [response.products objectAtIndex:0];
    NSLog(@"Products Available!");
    [self purchase:_product];
}
else if(!_product){
    NSLog(@"No products available");

}
}

- (void)purchase:(SKProduct *)product{
    SKPayment *payment = [SKPayment paymentWithProduct:product];

    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
    NSLog(@"received restored transactions: %lu", (unsigned long)queue.transactions.count);
    for(SKPaymentTransaction *transaction in queue.transactions){
        if(transaction.transactionState == SKPaymentTransactionStateRestored){

            NSLog(@"Transaction state -> Restored");

            [self buyBasicEdition];
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            break;
        }
    }
}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
    for(SKPaymentTransaction *transaction in transactions){

        switch(transaction.transactionState){
            case SKPaymentTransactionStatePurchasing: NSLog(@"Transaction state -> Purchasing");

                break;
            case SKPaymentTransactionStatePurchased:

                [self buyBasicEdition];
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                NSLog(@"Transaction state -> Purchased");
                break;
            case SKPaymentTransactionStateRestored:
                NSLog(@"Transaction state -> Restored");

                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:

                if(transaction.error.code == SKErrorPaymentCancelled){
                    NSLog(@"Transaction state -> Cancelled");

                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
        }
    }
}

-(void)buyBasicEdition {

    [[NSUserDefaults standardUserDefaults]setObject:@"low" forKey:@"points"];
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    SelectTeamVC *viewVc = [storyBoard instantiateViewControllerWithIdentifier:@"SelectTeamVC"];
    [self.navigationController  pushViewController:viewVc animated:YES];
}

Here is the button which I tap to initialise the payment process

- (IBAction)edition1:(id)sender {

    if([SKPaymentQueue canMakePayments]){
        NSLog(@"User can make payments");

        SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:_productId]];
        productsRequest.delegate = self;
        [productsRequest start];

    }
    else{
        NSLog(@"User cannot make payments due to parental controls");

    }

}

EDIT: The logs I am seeing on console

Taboo[1649:358442] User can make payments 2018-08-03 18:23:10.954499+0530 Taboo[1649:358442] Products Available! 2018-08-03 18:23:10.956229+0530 Taboo[1649:358442] Transaction state -> Purchasing

Bhavin Kansagara
  • 2,866
  • 1
  • 16
  • 20
  • can you see the logs for it? upto which logs you are getting response. Please add the logs your are getting on clicking the button. – Bhavin Kansagara Aug 03 '18 at 12:42
  • After tapping the button im getting the logs as follows........ Taboo[1649:358442] User can make payments 2018-08-03 18:23:10.954499+0530 Taboo[1649:358442] Products Available! 2018-08-03 18:23:10.956229+0530 Taboo[1649:358442] Transaction state -> Purchasing – Charishma Rao Aug 03 '18 at 12:55
  • It sounds like it's working fine but your testing procedure may be faulty. Did you create a sandbox user for testing purposes? Are you testing on a device? Did you remember to sign out of your normal iCloud identity? – matt Aug 03 '18 at 12:56
  • yes im testing in a device – Charishma Rao Aug 03 '18 at 12:59
  • NSLog for the transaction.error in case SKPaymentTransactionStateFailed: and share your logs – Bhavin Kansagara Aug 03 '18 at 13:18
  • 2018-08-04 10:09:39.255434+0530 Taboo[2278:492002] Transaction state -> Purchasing 2018-08-04 10:10:06.484380+0530 Taboo[2278:492002] Status bar could not find cached time string image. Rendering in-process. – Charishma Rao Aug 04 '18 at 04:40
  • I have kept the breakpoint and im getting response only for the case SKPaymentTransactionStatePurchasing: and for the remaining im not getting any response. – Charishma Rao Aug 04 '18 at 05:00
  • matt-- Hey what do you mean by sign out of my normal iCloud identity? can you please elaborate.... – Charishma Rao Aug 04 '18 at 05:25
  • Can any one help on this please, My app has been rejected only for this reason. Please help me on resolving this issue as soon as possible. – Charishma Rao Aug 06 '18 at 05:13

0 Answers0