1

アプリにアプリ内購入を実装することにしました。アプリケーションでアプリ内購入を使用して製品を購入する必要があります。このために、製品 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 に送信されました'」

たくさんのチュートリアルを参考にしました。これを使って購入するには?これから私を助けてください。どんな助けでも大歓迎です。前もって感謝します。

4

1 に答える 1

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。製品 ID は、Web の [アプリ内購入の管理] セクションで確認できます。

これを行うと、製品のリストが表示され、それらのいずれかを購入できます。

SKPayment *payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];
于 2012-08-30T09:46:11.087 に答える