简体   繁体   中英

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"

在此处输入图片说明

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

在此处输入图片说明在此处输入图片说明

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM