在应用程序购买中:产品信息未显示在购买视图控制器上

时间:2014-01-11 21:45:26

标签: ios objective-c in-app-purchase

我正在应用中设置InApp购买。

我有一个View Controller(主视图控制器),它有一个名为“Buy Access”的按钮。当我点击该按钮时,它正按照我应该的那样将我推送到下一个视图控制器(购买视图控制器)。

问题是,PurchaseViewController未显示InApp购买的任何信息。我为产品标题设置了UILabel出口,为产品说明设置了UITextView,但没有任何内容可以刷新或填写该文本。

产品ID位于MainViewController

关于什么被困的任何想法?

PurchaseViewController.h

@interface PurchaseViewController : UIViewController
<SKPaymentTransactionObserver, SKProductsRequestDelegate>

@property (strong, nonatomic) SKProduct *product;
@property (strong, nonatomic) NSString *productID;
@property (strong, nonatomic) IBOutlet UILabel *productTitle;
@property (strong, nonatomic) IBOutlet UIButton *buyButton;
@property (strong, nonatomic) IBOutlet UITextView *productDescription;
- (IBAction)buyProduct:(id)sender;
- (void)getProductInfo:(UIViewController *)viewController;

@property (nonatomic) int buttonNumber;

@end

PurchaseViewController.m

#pragma mark - SKProductsRequestDelegate
- (void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
    NSArray *products = response.products;
    if (products.count !=0) {
        _product = products[0];
        //_buyButton.enabled = YES;
        _productTitle.text = _product.localizedTitle;
        _productDescription.text = _product.localizedDescription;
    }
    else {
        _productTitle.text = @"Product not found";
    }

    products = response.invalidProductIdentifiers;

    for (SKProduct *product in products) {
        NSLog(@"Product not found: %@", product);
    }

}



- (IBAction)buyProduct:(id)sender {
    SKPayment *payment = [SKPayment paymentWithProduct:_product];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

#pragma mark SKPaymentTransactionObserver

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchased:
                [self unlockFeature];
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;

                case SKPaymentTransactionStateFailed:
                NSLog(@"Transaction Failed");
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;

            default:
                break;
        }
    }
}

修改: 我在productTitle中获得productDescriptionNSLog就好了,但是在PurchaseViewController加载时,它们的文本尚未更新。这些方法似乎在viewDidLoad后被调用。

1 个答案:

答案 0 :(得分:0)

更改了viewDidLoad的位置。愚蠢的错误。