Created
July 10, 2014 07:17
-
-
Save augustine-tran/10bd03176de58d0b43f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (IBAction)buyMoreButtonClicked:(id)sender | |
{ | |
[GGProgressHUD showActivity]; | |
NSString *productId = IAP_PRODUCT_CREDIT; | |
SKProduct *product = [[TNStoreHelper requestedProducts] valueForKey:productId]; | |
if (product) { | |
[self purchaseProduct:product]; | |
return; | |
} | |
[[TNStoreHelper sharedInstance] requestProducts:[NSSet setWithObject:productId] withCompletionHandler:^(BOOL success, NSArray *products) { | |
if (success && [products count] > 0) { | |
// we got the product here, now we just need to purchase it | |
[self purchaseProduct:[products objectAtIndex:0]]; | |
} else { | |
[GGProgressHUD hideActivity]; | |
} | |
}]; | |
} | |
- (void)purchaseProduct:(SKProduct *)product | |
{ | |
[GGProgressHUD showActivity]; | |
[[TNStoreHelper sharedInstance] buyProduct:product withCompletionHandler:^(BOOL buySuccess, SKPaymentTransaction *transaction, BOOL isRestore) { | |
if (buySuccess) { | |
// Purchase successed, we need to call webservice to verify and add credit for user | |
[GGWebService creditTopup:[NSNumber numberWithInt:score] didCompleted:^(NSHTTPURLResponse *response, id data, NSError *error) { | |
[GGProgressHUD hideActivity]; | |
}]; | |
} else { | |
[GGProgressHUD hideActivity]; | |
} | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment