Reputation: 1003
I've got a menu option that I want to protect with a $.99c in-App purchase. If the user has paid then the menu item is enabled, else, tapping on that menu item prompts them to buy.
Here is what I have so far. When I tap on the menu item it rightly invokes the apple IAP confirmation screen. Everything looks great so far, but, as soon as I click on "Buy", it errors out but am not sure how to trap on the error. The IAP is not performed.
Take a look.
Why would my PFPurchase method be failing?
How do I capture the error number coming back? (I am seeing "Error: (null)")
In my app delegate I have the following:
//////////////////////////////////////////////////////////////////////
/////// in-App Purchase //////
//////////////////////////////////////////////////////////////////////
hiLobetPURCHASED = NO;
// Use the product identifier from iTunes to register a handler.
[PFPurchase addObserverForProduct:@"hilobet100" block:^(SKPaymentTransaction *transaction) {
// Write business logic that should run once this product is purchased.
hiLobetPURCHASED = YES;
NSLog(@"observing purchases for hilobet100");
}];
and at the point of sale I have:
[PFPurchase buyProduct:@"hilobet100" block:^(NSError *error) {
NSLog(@"hang on trying to get it for you");
if (!error) {
NSLog(@"congrats, you are the proud owner of the hilo bet");
if ([switchHiLow isOn]) {
[btnSettingsHiLo setEnabled:YES];
[btnSettingsHiLo setHidden:NO];
} else {
[btnSettingsHiLo setEnabled:NO];
[btnSettingsHiLo setHidden:YES];
}
} else NSLog(@"there was an error in the purchase");
}];
All i get is the error message. See anything I'm missing?
Upvotes: 0
Views: 105
Reputation: 1003
Once I got the error message to spit out properly (see answer candidate #1) I then was able to look up the error message to see that there is a lot of chatter out there saying that the IAP testing works fine with real phone but not as fine with simulators... I tried on my phone and the above code works.
Upvotes: 0
Reputation: 223
If you want to see the specific error failing in the buyProduct call, change
NSLog(@"there was an error in the purchase");
to
NSLog(@"there was an error (error: %@) in the purchase", error);
Upvotes: 1