milanjansari
milanjansari

Reputation: 1549

Error Domain=SKErrorDomain Code=3 "Cannot connect to iTunes Store" UserInfo=0x1aaf40 {NSLocalizedDescription=Cannot connect to iTunes Store}

Currently I'm working on in-App Purchase functionality, and I am getting below of the error

"Error Domain=SKErrorDomain Code=3 "Cannot connect to iTunes Store" UserInfo=0x1aaf40 {NSLocalizedDescription=Cannot connect to iTunes Store}"

Here is the step.

1) First I have create a one application "inAppPro" and it is under (Status) : "Prepare for upload"

enter image description here

2) I have added 4 Non-Consumable product. and also fill related details.

enter image description here enter image description here

3) I have also create test user (sandbox) for test in-App purchase product.

4) I have also created provision profile with enable inApp Purchase.

5) I have also created APP ID without (*) wild card.

Here is the code which are currently I'm using.

- (void)viewDidLoad
{
   Detail1 *observer = [[Detail1 alloc] init];

   [[SKPaymentQueue defaultQueue] addTransactionObserver:observer];

   [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}


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

    if ([SKPaymentQueue canMakePayments])
    {
        NSString *product = [NSString stringWithFormat:@"com.companyname.inAppDemo.module%d",ApplicationDelegate.objectID];
        NSLog(@"In-App product for request = %@", product);

        SKPayment *payment = [SKPayment paymentWithProductIdentifier:product];
        [[SKPaymentQueue defaultQueue] addPayment:payment];


    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"You are not authorized to purchase from AppStore"
                                                       delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
    for (SKPaymentTransaction *transaction in transactions)
    {
        switch (transaction.transactionState)
        {
            case SKPaymentTransactionStatePurchased:

                [self completeTransaction:transaction];

                break;

            case SKPaymentTransactionStateFailed:

                [self failedTransaction:transaction];

                break;

            case SKPaymentTransactionStateRestored:

                [self restoreTransaction:transaction];

            default:

                break;
        }           
    }
}
- (void) failedTransaction: (SKPaymentTransaction *)transaction
{   
    if (transaction.error.code != SKErrorPaymentCancelled)      
    {       
        // Optionally, display an error here.   
        NSLog(@"%@",transaction.error);

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

- (void) completeTransaction: (SKPaymentTransaction *)transaction
{       
    //[[MKStoreManager sharedManager] provideContent: transaction.payment.productIdentifier];   
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 
}

- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{   
    //[[MKStoreManager sharedManager] provideContent: transaction.originalTransaction.payment.productIdentifier];   
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 
}
-(IBAction)btnpurchase:(id)sender
{
    NSLog(@"ProductStatus = %@", ApplicationDelegate.productStatus);

    if ([ApplicationDelegate.productStatus isEqualToString:@"FREE"]) 
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"This is free for you so ENJOY it!!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
        [alert show];
        [alert release];
    }
    else if ([ApplicationDelegate.productStatus isEqualToString:@"PAID"]) 
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"You have already purchase it!!!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
        [alert show];
        [alert release];
    }
    else
    {
        NSLog(@"Detail1 id for product = %d", ApplicationDelegate.objectID);
        NSString *product = [NSString stringWithFormat:@"com.companyname.inAppDemo.module%d",ApplicationDelegate.objectID];
        NSLog(@"In-App product-id = %@", product);



        SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObjects:product,nil]]; 
        request.delegate = self;
        [request start];

    }
}

Please anyone help me out.

Thanks in advance.

Upvotes: 0

Views: 3976

Answers (1)

Bilge
Bilge

Reputation: 44

You must have valid contracts in effect in the "Contracts, Tax, and Banking" Section. And of course, make sure that you use a correct Provisioning Profile and that you have enabled in App Purchase for that ID, and (last) that you have added purchasable items in iTunes Connect (which you did, as your screenshots show).

Upvotes: 3

Related Questions