While testing In-App-Purchase in the SANDBOX ENVIRONMENT on the device, I'm logging the following error :
Error Domain=SKErrorDomain Code=0 "Cannot connect to iTunes Store" UserInfo=0x2916a0 {NSLocalizedDescription=Cannot connect to iTunes Store}.t
I'm able to retreive the product id's which i registered through iTunes Connect. I'm displaying data related with these products as in a table view along with Buying option. When i try to buy a product a transaction is initiated but it doesn't ask me for any test user details & i get the error as mentioned above.
I'm providing the code which I implemented.
//the below code is for RETREIVING THE PRODUCT id's
#pragma mark Store kit
-(IBAction)sendProductInfoRequest{
NSLog(@"sendProductInfoRequest");
NSSet *identifiersSet=[NSSet setWithObjects:[NSString stringWithFormat:@"%@",@".15April2011"],[NSString stringWithFormat:@"%@",@"15April201102"],nil];
SKProductsRequest *productRequest=[[SKProductsRequest alloc] initWithProductIdentifiers:identifiersSet];
productRequest.delegate=self;
[productRequest start];
NSLog(@"completing sendProductInfoRequest");
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSLog(@"yoooo!");
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);
}
}
/the BuyProducts method is called when user clicks buy button related to a particular product
-(IBAction)BuyProducts
{
if ([SKPaymentQueue canMakePayments])
{
[self makePaymentRequestForThisProduct:isbnText.text];
}
}
-(void)makePaymentRequestForThisProduct:(NSString*)productID
{
SKPayment *payment = [SKPayment paymentWithProductIdentifier:productID];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
/I have added the transaction observer in applicationDidFinishLaunching method of AppDelegate
//Transaction Observer is a class
TransactionObserver *observer;
observer = [[TransactionObserver alloc] init];
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];
//the TransactionObserver.m class
@implementation TransactionObserver
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
NSLog(@"failed transaction");
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
}
}
- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
NSLog(@"successful purchase");
// [self recordTransaction: transaction];
//[self provideContent: transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
NSLog(@"restored incomplete transaction");
// [self recordTransaction: transaction];
// [self provideContent: transaction.originalTransaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
- (void) failedTransaction: (SKPaymentTransaction *)transaction
{
NSLog(@"The error description is:%@",[transaction.error description]);
if (transaction.error.code != SKErrorPaymentCancelled)
{
if(transaction.error.code == SKErrorUnknown) {
NSLog(@"Unknown Error (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
if(transaction.error.code == SKErrorClientInvalid) {
NSLog(@"Client invalid (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
if(transaction.error.code == SKErrorPaymentInvalid) {
NSLog(@"Payment invalid (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
if(transaction.error.code == SKErrorPaymentNotAllowed) {
NSLog(@"Payment not allowed (%d), product: %@", (int)transaction.error.code, transaction.payment.productIdentifier);
UIAlertView *failureAlert = [[UIAlertView alloc] initWithTitle :@"In-App-Purchase Error:"
message: @"There was an error purchasing this item please try again."
delegate : self cancelButtonTitle:@"OK"otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
}
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}
@end
In-app purchases allow developers to offer the app for free in the App Store (for iOS) and Google Play (for Android). Then, within the application, they can upsell and advertise paid upgrades, locked features, special items, and other premium offers.
Apple App Store: 30 percent standard commission on apps and in-app purchases of digital goods and services; sales of physical products are exempt.
On the Google Play Store app, in-app purchases will be by the Price or Install button. On play.google.com/store, you'll see "Offers in-app purchases" below the name of the app.
This may be ridiculous, but -- if you're certain your code is correct -- do a hard reset (full wipe) of your iPod (Settings => General => Reset => Erase All Content and Settings).
It also happens if you are logged in with some other iTunes Account. To test the In App purchase in Sandbox box you need to log out from any other account from Setting. Then launch your application and Do in App Purchase. When your account is asked enter the one you created as iTunes Test Account. This way your Sandbox environment would work perfectly. Hope this would be helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With