2012-10-25 27 views
0

我有一個非常有趣的問題。這似乎應該很容易解決,但也許我只是在想它?在應用程序採購與IBAction /按鈕

Brief: 我想使用IBAction按鈕來激活購買而不是表格視圖。

詳細說明:

首先,我使用本教程作爲指南。 (A偉大的教程 - 檢查出來謝謝,雷!) http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial

  1. 如果您向下滾動到那裏說:

    - (void)buyButtonTapped:(id)sender { 
    
    UIButton *buyButton = (UIButton *)sender; 
    SKProduct *product = _products[buyButton.tag]; 
    
    NSLog(@"Buying %@...", product.productIdentifier); 
    [[RageIAPHelper sharedInstance] buyProduct:product]; } 
    

這是我在哪裏卡住。該示例使用表視圖,但我不想在我的應用程序中使用其中的一個。我想要做的就是使用手動創建的IBAction按鈕。

所以我做了這個按鈕,並且把它連接起來並使它和NSLog一起工作。

-(IBAction)buyProductButton:(id)sender { 

    NSLog(@"Buy Something."); 

} 

所以我的問題是我放什麼東西在這個IBAction爲代替

- (void)buyButtonTapped:(id)sender { 

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

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

,以獲得該按鈕來激活購買?

也許這樣?

-(IBAction)buyProductButton:(id)sender { 

    SKProduct *product = _products; 

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

但yeaaa,它不起作用。

任何想法將大大&大量讚賞。

謝謝!

回答

0

你不設置正確的產品:

SKProduct *product = _products[buyButton.tag]; 

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

嘗試使用你的產品標籤,其中buyButton.tag

+0

由於我沒有使用合併「byButton.tag」的表格視圖,我只是想手動購買產品。那麼如果它在IBAction按鈕中,我該如何購買這款產品呢? –

+0

我是否將com.companyname.appname.iapname替換爲buyButton.tag?我想我不理解。抱歉。 –

+0

那麼你是否有產品的標識符? –

0

這裏是我試圖和它的工作的代碼。我使用了一個按鈕來使用下面的代碼進行特定的購買。

在M檔的@interface創建變量數組_產品展示:

@interface ....(){ 

    NSArray *_products; 

} 

將這個您viewDidLoad方法:

[[RageIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) { 

     if (success) { 

      _products = products; 

     } 
    }]; 

上面的代碼將填補 「_產品展示」 的產品(你已經在商店註冊了。 並在按鈕功能中使用下面的代碼來購買產品。

SKProduct *product = _products[0];  
[[RageIAPHelper sharedInstance] buyProduct:product]; 

我在「_產品展示[0]」指店面產品中使用「0」 ..如果你有很多的產品,你可以使用[中_產品展示[]的]對應數字買特定項目。