Payal Gosar
Payal Gosar

Reputation: 11

in app purchase non consumable product

I have written the following code.

But when i execute this code, i got log, which shows "no products available". I am unable to find the reason.

-(void)viewDidLoad {

    [super viewDidLoad];

if ([SKPaymentQueue canMakePayments]) 
{

SKProductsRequest *productsRequest=[[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:@"com.cmp.name.prdt"]];

productsRequest.delegate=self;
[productsRequest start];

}

else {
NSLog(@"Parental Control are enabled");
}

}


-(IBAction)btnpurchase

{

NSString* isPurchased = [[NSUserDefaults standardUserDefaults] stringForKey:@"com.cmp.name.prdt"];

if ([@"purchased" compare:isPurchased]==NSOrderedSame)
{

///do some task

}

else
{

SKPayment * payment=[SKPayment paymentWithProductIdentifier:@"com.cmp.name.prdt"];
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] addPayment:payment];

}

}


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

{

SKProduct *validProduct=nil;

int count=[response.products count];

if (count>0) {

validProduct=[response.products objectAtIndex:0];

}

else if(!validProduct)

{

NSLog(@"no products available");

}

}

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{

for (SKPaymentTransaction *transaaction in transactions)

{

switch (transaaction.transactionState)

{

case SKPaymentTransactionStatePurchasing:

break;

case SKPaymentTransactionStatePurchased:

[[SKPaymentQueue defaultQueue]finishTransaction:transaaction];
[[NSUserDefaults standardUserDefaults] setObject:@"purchased" forKey:@"com.cmp.name.prdt"];
[[NSUserDefaults standardUserDefaults] synchronize];

break;

case SKPaymentTransactionStateRestored:

[[SKPaymentQueue defaultQueue]finishTransaction:transaaction];

break;

case SKPaymentTransactionStateFailed:

if (transaaction.error.code!=SKErrorPaymentCancelled) {

NSLog(@"Error encountered");

}

[[SKPaymentQueue defaultQueue] finishTransaction:transaaction];

break;

default:

break;

}

}

}

Could anyone help me out in this?

Upvotes: 1

Views: 1213

Answers (2)

Pranav Jaiswal
Pranav Jaiswal

Reputation: 3752

You can try out with following piece of code //PRODUCT REQUEST DELEGATE METHOD

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

    NSLog(@"The product request didReceiveResponse :%@",[response description]);
    NSLog(@"The products are :%@",[response.products description]);

    NSLog(@"The invalidProductIdentifiers are:%@",[response.invalidProductIdentifiers description]);

    NSArray *products=response.products;


    for(SKProduct *currentProduct in products){

         NSLog(@"THE Product price is :%@",currentProduct.price);
         NSLog(@"THE Product description is :%@",currentProduct.localizedDescription);
         NSLog(@"THE Product title is :%@",currentProduct.localizedTitle);
         NSLog(@"THE Product's product identifier is :%@",currentProduct.productIdentifier);

         }

}

THIS WILL LOG THE PRODUCT DETAILS REGISTERED ON iTUNES CONNECT IN CONSOLE WINDOW

Upvotes: 1

Daniel Blezek
Daniel Blezek

Reputation: 4549

Unfortunately, Apple does not respond with any useful information about why your purchases do not show up. I would go through this checklist. In my apps, things didn't work for a few days, then the suddenly started working. Be sure your financial info is correct.

Upvotes: 0

Related Questions