2012-08-30 61 views
1

我在应用程序中实施了应用程序内购买。我需要在应用程序中使用应用内购买来购买产品。为此,我使用iTunes a/c添加了我的产品app_id。iphone sdk应用程序内购买错误

这里是我的代码参考,

代码:

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; 
} 

现在我的控制台窗口接收我的web服务的所有APP_ID的。

我添加了IAPHelper,InAppRageIAPHelper,MBProgressHUD,Reachability类到我的项目中的In-App购买所需的类。

-(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]; 
} 

这里的时候,我攻购买按钮我的应用程序得到坠毁,得到以下错误, “终止应用程序由于未捕获的异常‘NSInvalidArgumentException’,原因是:“ - [__ NSCFString objectForKey:]:无法识别的选择发送到实例0x9154ad0'“

我介绍了很多tutorials.How购买使用这个?请帮我解决这个问题。任何帮助将不胜感激。提前致谢。

回答

1

这是崩溃的代码

[[appidArray objectAtIndex: productIndex] objectForKey: @"app_store_id"] 

这最有可能是因为[appidArray objectAtIndex: productIndex]返回一个字符串,而不是一本字典。

第一步:你需要加载从商店的物品是这样的:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self]; 
SKProductsRequest *productsRequest = [[[SKProductsRequest alloc] initWithProductIdentifiers:yourProductIdentifiers autorelease]; 
productsRequest.delegate = self; 
[productsRequest start]; 

PS。你可以在网上找到你的产品标识,在管理应用程式内这样做后购买区

,您将收到的产品清单,并购买任何他们:

SKPayment *payment = [SKPayment paymentWithProduct:product]; 
[[SKPaymentQueue defaultQueue] addPayment:payment]; 
+0

那么好吧。所有的app_id都在我的数组中。现在我该怎么办?使我的产品购买? – Saranya

+0

编辑我的答案.. – Vlad