gpt4 book ai didi

ios - UILabel 未显示应用内购买标题

转载 作者:行者123 更新时间:2023-11-29 03:21:09 27 4
gpt4 key购买 nike

我正在获取我的应用内购买 Title(我可以在 NSLog 中看到它),但是显示标题的 UILabel 获取在 viewDidLoad 之后调用。有什么方法可以在 viewDidLoad 之前获取标题,以便 UILabel 显示标题

下面是我的代码。如果您需要我发布更多信息,请告诉我,谢谢!

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;
}
}
}

最佳答案

通常的架构是在显示包含信息的 View 之前获取产品信息。然后在创建 View Controller 并显示其 View 时将该信息传递给 View Controller 。

关于ios - UILabel 未显示应用内购买标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21079139/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com