アプリにアプリ内購入を実装することにしました。アプリケーションでアプリ内購入を使用して製品を購入する必要があります。このために、製品 app_id を iTunes a/c に追加しました。
ここに私のコードリファレンスがあります、
コード:
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 クラスなどのアプリ内購入に必要なクラスをプロジェクトに追加しました。
-(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 に送信されました'」
たくさんのチュートリアルを参考にしました。これを使って購入するには?これから私を助けてください。どんな助けでも大歓迎です。前もって感謝します。