Reputation: 798
How can i check the in app purchase without making the actual payment.Do I have to upload the build on iTunes to check for in app purchase. I created the product Id in iTunes and also a sandbox user to test. But i have no idea how to proceed next.
Upvotes: 4
Views: 189
Reputation: 798
After a long RnD,i found the solution for it. -Firstly you have to create a product Id in itunes after entering all the information and before that make sure that all the bank,tax and account info is filled in agreement. -You also have to take a screen shot of the screen asking for in app purchase. -After that enable the in app purchase in the xcode capabilities. -Import framework -Import IAPHelper and RageIAPHelper class into your project -In your viewcontroller.h class add these
NSArray *_products;
NSNumberFormatter * _priceFormatter;
-(void)viewdidload
{
[self reload];
[[RageIAPHelper sharedInstance] restoreCompletedTransactions];
_priceFormatter = [[NSNumberFormatter alloc] init];
[_priceFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[_priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
}
- (void)restoreTapped:(id)sender {
[[RageIAPHelper sharedInstance] restoreCompletedTransactions];
}
- (void)productPurchased:(NSNotification *)notification {
NSString * productIdentifier = notification.object;
[_products enumerateObjectsUsingBlock:^(SKProduct * product, NSUInteger idx, BOOL *stop) {
if ([product.productIdentifier isEqualToString:productIdentifier]) {
*stop = YES;
NSLog(@" productPurchased");
}
- (void)reload {
_products = nil;
[[RageIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {
if (success) {
_products = products;
}
}];
}
- (void)buyButtonTapped {
SKProduct *product = _products[0];
NSLog(@"Buying %@...", product.productIdentifier);
if(product!=nil)
{
[[RageIAPHelper sharedInstance] buyProduct:product];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Confirm Your In-App Purchase"
message:@"Subscription is required to access thi sfeature."
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Buy", nil];
[alert show];
}
}
-(void)viewwillappear
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productPurchased:) name:IAPHelperProductPurchasedNotification object:nil];
}
in IAPHelper.m
- (void)provideContentForProductIdentifier:(NSString *)productIdentifier {
if ([productIdentifier isEqualToString:@"com.abc.productName"]) {
int currentValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"com.abc.productName"];
}
here replace "com.abc.productName" with your product Id which you created. This is all in the code part To test the in app purchase- log out of the existing apple id in phone settings and log in with the sandbox user you created from itunes. and then you can check it without actual payment.
To download IAPHelper class and for documentation refer : https://github.com/saturngod/IAPHelper
Upvotes: 4