Reputation: 81
During tests, in-app purchasing seemed to work well, but after release it just stopped. Afer I press the 'upgrade' button, it asks for my password and then nothing. Not even an error message.
I've browsed StackOverflow for a while and found these questions:
In app purchase does not work when live
In App Purchase not working after it has been approved
I thought I just needed to wait but there was no one who waited more than 48 hours. For me, it's been 120 hours after the release. So I considered it may be something with my code.
My algorithm is based upon thus Ray Wenderlich's tutorial http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial
Firstly, in `applicationDidFinishLaunchingWithOptions: in my app delegate
// In app
[myGuideIAP sharedInstance]; //initialize singleton
[[myGuideIAP sharedInstance] tryLoadingProduct]; //my method to load SKProduct
//SKProduct is stored as a @property in the singleton
Later, in the upgrade view controller, I check and if it didn't load the product, execute the tryloadingProduct
once again.
Singleton is initialized the classic way:
+ (myGuideIAP *)sharedInstance {
static dispatch_once_t once;
static myGuideIAP * sharedInstance;
dispatch_once(&once, ^{
NSSet * productIdentifiers = [NSSet setWithObjects:
@"com.mkochukov.myguidemind.proupgrade",
nil];
sharedInstance = [[self alloc] initWithProductIdentifiers:productIdentifiers];
});
return sharedInstance;
}
This is what's inside tryLoadingProduct
method:
- (void)tryLoadingProduct
{
[[myGuideIAP sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products)
{
if (success) {
if (products.count > 0)
_mProduct = products[0];
}
}];
}
When the user tries to purchase, an alert view appears, asking to buy or restore. This is how it's handled
-(void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == alertView.cancelButtonIndex)
return;
if (buttonIndex == 0) {
[[myGuideIAP sharedInstance] buyProduct:[myGuideIAP sharedInstance].mProduct];
}else if (buttonIndex == 1){
[[myGuideIAP sharedInstance]restoreCompletedTransactions];
}
}
And after that when user hits the "Buy" button this is executed:
- (void)buyProduct:(SKProduct *)product {
NSLog(@"Buying %@...", product.productIdentifier);
SKPayment * payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
Upvotes: 2
Views: 782