Reputation: 1741
I've just added iAP in my app and i get an error.
- (void)getProductID { //runs on viewdidload
if ([SKPaymentQueue canMakePayments]) {
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObjects:_productID, nil]];
request.delegate = self;
[request start];
} else {
[[[UIAlertView alloc] initWithTitle:@"Serpentine" message:@"Error: Could not connect to store. Try enabling in-app-purchases in settings." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
[self couldNotConnectToStore];
}
}
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:[self unlockPurchase];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
case SKPaymentTransactionStateFailed:NSLog(@"Transation Failed");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
default:break;
}
}
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSArray *products = response.products;
if (products.count != 0) {
_product = products[0];
_allowPurchase = YES;
} else {
[[[UIAlertView alloc] initWithTitle:@"Serpentine" message:@"Error: Could not connect to store" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];//this line of code runs a second after the controller opens
//****************** error on line above *********************************
[self couldNotConnectToStore];
}
products = response.invalidProductIdentifiers;
for (SKProduct *product in products) {
NSLog(@"Product not found: %@", product);
}
}
- (IBAction)purchaseButtonPressed:(UIButton *)sender {
if (sender.tag == 1) {
//buy 20
_productID = @"com.piguygames.serpentine.buy20";
SKPayment *payment = [SKPayment paymentWithProduct:_product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
} else if (sender.tag == 2) {
//buy 45
} else if (sender.tag == 3) {
//buy 100
} else if (sender.tag == 4) {
//double
} else if (sender.tag == 5) {
//remove ads
}
}
Note: there is some other code in the controller, but i don't think it is relevant.
I have added the in app purchase to iTunes connect and it says "ready to submit". So should it be fine here? Also I got a warning on that same site saying that I must submit a new version of my app to get in app purchases working. I decided I would submit my app and disable the iAP in the app first, then release the iAP in a later update. Do you need to submit a new version to test the iAP?
Anyway, are there any problems you can see so far?
Please do ask for more information if there is more needed, I am a beginner with this topic. Thanks
Upvotes: 1
Views: 2476
Reputation: 7351
Make sure that you're signed out of any iTunes account in the Settings app, unless it's a test account you created in iTunes Connect. I recently had this exact same problem and that's how I solved it.
Upvotes: 1