我正在应用中设置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
中获得productDescription
和NSLog
就好了,但是在PurchaseViewController
加载时,它们的文本尚未更新。这些方法似乎在viewDidLoad
后被调用。
答案 0 :(得分:0)
更改了viewDidLoad的位置。愚蠢的错误。