0

hi i have implemented storeKit in my ios app, this is the code:

-(IBAction)Purchase:(id)sender{
SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"month"];
[[SKPaymentQueue defaultQueue]addTransactionObserver:self];
[[SKPaymentQueue defaultQueue]addPayment:payment];
}


-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
    SKProduct *VailProduct = nil;
    int count = [response.products count];
    if (count>0) {
        VailProduct = [response.products objectAtIndex:0];
    } else if (!VailProduct){
        UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"LOG" message:@"No Products Are Availble!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [theAlert show];
        [theAlert release];

    }

}

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
        case SKPaymentTransactionStatePurchasing:

                break;
                case SKPaymentTransactionStatePurchased:
                [self EnableEmergencyCenter];
                [[SKPaymentQueue defaultQueue]finishTransaction:transaction];
                break;

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

                case SKPaymentTransactionStateFailed:
                if (transaction.error.code != SKErrorPaymentCancelled) {
                    UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"LOG" message:[NSString stringWithFormat:@"%@",transaction.error] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
                    [theAlert show];
                    [theAlert release];

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

this comes on the viewDidLoad :

if ([SKPaymentQueue canMakePayments])
{
     // Display a store to the user.
    UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"LOG" message:@"Device Can Make Payments!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [theAlert show];
    [theAlert release];

    SKProductsRequest *ProductRequst = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:@"month"]];
    ProductRequst.delegate = self;
    [ProductRequst start];
}
else {
     // Warn the user that purchases are disabled.
    UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"LOG" message:@"Device Can't Make Payments!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [theAlert show];
    [theAlert release];
}

the product identifier are currect but i keep gettin this error called from the switch statement

    case SKPaymentTransactionStateFailed:
        if (transaction.error.code != SKErrorPaymentCancelled) {
            UIAlertView *theAlert = [[UIAlertView alloc]initWithTitle:@"LOG" message:[NSString stringWithFormat:@"%@",transaction.error] delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [theAlert show];
            [theAlert release];

help please :)

Baby Groot
  • 4,609
  • 39
  • 50
  • 67
or azran
  • 3,955
  • 9
  • 34
  • 65

2 Answers2

1

Since this question has been asked a year ago, i guess the problem is already solved, but i'll try my luck anyway.

Try following things:

  • create a new provisioning profile, install it and sign your app with it. Sometimes the old profiles won't really be updated when you edit them and therefore the payment process wont work.
  • If you receive the products correctly and you previously have installed a iTunes Version of your app, than you need to delete the app from your device and install it via XCode.

Hope it helps

EDIT:

This could also help you

Error Domain=SKErrorDomain Code=0 “Operation could not be completed. (SKErrorDomain error 0.)”

Community
  • 1
  • 1
NicTesla
  • 1,616
  • 5
  • 21
  • 35
1

The purchase is failing because the transaction is technically failing, and this is not specifically due to the fact that it cannot connect... it can be due to a number of reasons. Double check that the product identifier is correct. I think that your issue is most likely that you are not signing your app with a development certificate that is linked to the App ID used for your app. In iTunes Connect, what app ID is your app linked to? It needs to be an app ID SPECIFICALLY for that app (i.e. com.ChillySky.InAppPurchaseApp, NOT com.ChillySky.*), no wildcards! Also, you need to generate a special development certificate to test this app on your device. IT MUST BE LINKED TO THE CORRECT APP ID!! If any of this is not correct, your in app purchase will not go through. This was the biggest issue for me. Hope this helps!

Jack Humphries
  • 12,423
  • 14
  • 77
  • 119