2

Ray Wenderlich のチュートリアルを使用して IAP を作成しています (http://www.raywenderlich.com/23266/) 。すべてうまく機能しますが、アプリでテーブル ビューを使用したくありません。購入するための IBAction ボタン。

つまり、基本的にこれがテーブルビューでの動作です。最初に製品を特定します。

 + (RageIAPHelper *)sharedInstance {
     static dispatch_once_t once;
     static RageIAPHelper * sharedInstance;
     dispatch_once(&once, ^{
         NSSet * productIdentifiers = [NSSet setWithObjects:
                                       @"com.companyname.10coins",
                                       @"com.companyname.20coins",
                                       nil];
         sharedInstance = [[self alloc] initWithProductIdentifiers:productIdentifiers];
     });
     return sharedInstance;
 }

次に、アクションをトリガーします。

 - (void)buyButtonTapped:(id)sender {

        UIButton *buyButton = (UIButton *)sender;
        SKProduct *product = _products[buyButton.tag];

        NSLog(@"Buying %@...", product.productIdentifier);
        [[RageIAPHelper sharedInstance] buyProduct:product]; }


     - (void)buyProduct:(SKProduct *)product {

         NSLog(@"Buying %@...", product.productIdentifier);

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

だから私は、次のように、アクションをトリガーするための単純なボタンを作成しようとしています:

 - (IBAction)button10Coins:(id)sender {

     SKPayment * payment = [SKPayment paymentWithProduct:@"com.companyname.10coins"];
     [[SKPaymentQueue defaultQueue] addPayment:payment];
 }

しかし、「互換性のないポインター型」という警告が表示されます。

開始後、コードはうまく機能し、購入を完了することができました。唯一の問題は、IBAction を適切に作成することです。何か案は?

ありがとう!!!

4

3 に答える 3

3

すべての接続作業が完了し、コードの下にフレームワークを追加すると、確実に機能します。

define kStoredData @"アプリ内購入のオブジェクト" (これはオブジェクト宣言用です)

- (void) requestProductData
{
    if(countphotoval==2)
    {
        phonetext.text=@"";
        countrycode.text=@"";
        nametext.text=@"";
        Emailtext.text=@"";
        photocounter=0;
        image1.image=[UIImage imageNamed:@"image-box.png"];
        image2.image=[UIImage imageNamed:@"image-box.png"];
        labelimage.text=@"Image";
        addbuttonforpicker.userInteractionEnabled=true;
        addbuttonforpicker2.userInteractionEnabled=false;
        countphotoval=0;
    }
    request= [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: @"object of inapp purchase"]];
    request.delegate = self;
    
    [request start];
    
      
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    NSArray *myProduct = response.products;
    
    
    // populate UI
  
    }


-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        NSLog(@"transaction array-->%@",transaction.description);
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchasing:
                
                // show wait view here
                //statusLabel.text = @"Processing...";
                break;
                
            case SKPaymentTransactionStatePurchased:
                
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                [NSThread detachNewThreadSelector:@selector(startActivityindicatore) toTarget:self withObject:nil];
                [self fordataupload];
                
                break;
                
            case SKPaymentTransactionStateRestored:
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
                
            case SKPaymentTransactionStateFailed:
                
                if (transaction.error.code != SKErrorPaymentCancelled) {
                    NSLog(@"Error payment cancelled");
                    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Sorry" message:@"Please provide correct Userid and Password" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
                    [alert show];
                    [alert release];
                    //                    [self dismissModalViewControllerAnimated:YES];
                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                // remove wait view here
                // statusLabel.text = @"Purchase Error!";
                break;
                
            default:
                break;
        }
    }
}


- (void) failedTransaction: (SKPaymentTransaction *)transaction
{
    if (transaction.error.code != SKErrorPaymentCancelled)
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Something has went wrong" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];

    }
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
    //If you want to save the transaction
    // [self recordTransaction: transaction];
    
    //Provide the new content
    // [self provideContent: transaction.originalTransaction.payment.productIdentifier];
    
    //Finish the transaction
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
    
}

- (void) completeTransaction: (SKPaymentTransaction *)transaction
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congrats!!" message:@"Your Transaction Is Completed" delegate:self cancelButtonTitle:@"Thanx!" otherButtonTitles:nil];
    [alert show];
    [alert release];

    //If you want to save the transaction
    // [self recordTransaction: transaction];
    
    //Provide the new content
    //[self provideContent: transaction.payment.productIdentifier];
    
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
    
}
-(void)requestDidFinish:(SKRequest *)request1  
{  
    [self stopActivityindicatore];
    SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"VirtualBinocularsContest1"];
    NSLog(@"quality --->%d",payment.quantity);
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
    [request release];
}  

それがあなたのために働くかどうか通知してください.. :)

于 2013-01-05T04:36:59.800 に答える
2

paymentWithProduct:引数を期待しSKProduct *、あなたは。を渡していNSStringます。_productsあなたはあなたの配列からあなたの製品を取り出して、代わりにそれを渡す必要があります。

于 2013-01-05T04:04:27.243 に答える