I struck in implementing In-app Purchase in my application. I need to purchase products using in-app purchase in my application. For this i added my products app_id with my iTunes a/c.
Here is my code reference,
Code:
ViewController.m
NSMutableArray *featuredappidArray;
- (void)viewDidLoad
{
[super viewDidLoad];
featuredappidArray=[[NSMutableArray alloc]init];
}
-(void)parseRecentPosts:(NSString*)responseString
{
NSString *app_store_id = [NSString stringWithFormat:@"%@",[post objectForKey:@"app_store_id"]];
NSLog(@"Recent Post app_store_id: %@",app_store_id);
[featuredappidArray addObject:app_store_id];
indexvalue=ndx;
}
- (void)buttonTapped:(UIButton *)sender
{
[detailview Receivedappidurl:featuredappidArray idx:indexvalue];
}
DetailViewController.h
-(void)Receivedappidurl:(NSMutableArray*)recentappidArray idx:(int)index;
DetailViewController.m
NSMutableArray *appidArray;
-(void)Receivedappidurl:(NSMutableArray*)recentappidArray idx:(int)index
{
NSLog(@"recentappidArray:%@",recentappidArray);
appidArray=recentappidArray;
}
Now my console window receives all app_id’s from my web service.
I added the necessary classes for In-App purchase like IAPHelper, InAppRageIAPHelper,MBProgressHUD,Reachability classes into my project.
-(IBAction)purchaseButton
{
NSLog(@"appidarray:%@",appidArray);
NSLog(@"pdt index:%d",productIndex);
NSLog(@"APPLe indentifier:%@",[[appidArray objectAtIndex: productIndex] objectForKey: @"app_store_id"]);
[InAppRageIAPHelper sharedHelper].productIndex = productIndex;
[[InAppRageIAPHelper sharedHelper] buyProductIdentifier:[[appidArray objectAtIndex: productIndex] objectForKey: @"app_store_id"]];
self.hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
_hud.labelText = @"Buying Book...";
[self performSelector:@selector(timeout:) withObject:nil afterDelay:60*5];
}
Here when am tapping the buy button my app getting crashed and getting the following error,
” Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSCFString objectForKey:]: unrecognized selector sent to instance 0x9154ad0’ “
I referred many tutorials.How to purchase using this? Please help me out of this. Any help will be greatly appreciated. Thanks in advance.
This is crashing your code
This most likely is because
[appidArray objectAtIndex: productIndex]returns a string, and not a dictionary.First step: you need to load the items from the store like this:
PS. you can find your product identifiers on the web, in the Manage InApp Purchases section
after doing this, you will receive a list of products, and to purchase any of them: