第一次使用XCODE和Objective C.在我的SKProductRequest方法中,我的UIButtons和UILabels出现问题。
下面是我的ShopViewController.m,最初调用我的3个UIButtons和我的UILabel。在viewDidLoad中,我的UIButtons和Label都有内容。
我的Shop页面正确加载但是一旦调用ProductsRequest方法,UIButtons和UILabels就变为零,不知道为什么。所有项目都是.h文件中的(强大的,非原子的)属性,并且已链接到ShopViewController中的引用Outlets。任何帮助都非常感谢。
产品请求下方的ShopViewController.m是使用GetProductInfo方法生成的。当我按下主游戏viewController上的购买按钮时,从我的* homeViewController调用。
#import "ShopViewController.h"
#import "ViewController.h"
@interface ShopViewController ()
@property (strong, nonatomic) ViewController *homeViewController;
@end
@implementation ShopViewController
@synthesize fvProductTitle;
- (void)viewDidLoad {
[super viewDidLoad];
_fvBuyButton.enabled = YES;
_ddBuyButton.enabled = NO;
_bundleBuyButton.enabled = NO;
fvProductTitle.text = @"don't read this";
}
- (IBAction)buyFVProduct:(id)sender {
SKPayment *payment = [SKPayment paymentWithProduct:_fvProduct];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (IBAction)buyDDProduct:(id)sender {
SKPayment *payment = [SKPayment paymentWithProduct:_ddProduct];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (IBAction)buyBundleProduct:(id)sender {
SKPayment *payment = [SKPayment paymentWithProduct:_bundleProduct];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (void) getProductInfo:(ViewController *) viewController {
_homeViewController = viewController;
if ([SKPaymentQueue canMakePayments])
{
SKProductsRequest *request = [[SKProductsRequest alloc]
initWithProductIdentifiers:
[NSSet setWithObjects:self.bundleProductID, self.ddProductID, self.fvProductID, nil]];
request.delegate = self;
[request start];
}
else{
_fvProductDescription.text = @"please enable app purchases";
}
}
#pragma mark -
#pragma mark SKProductsRequestDelegate
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSArray *products = response.products;
if (products.count != 0)
{
_fvProduct = products[2];
_fvBuyButton.enabled = YES;
fvProductTitle.text = _fvProduct.localizedTitle;
_ddProduct = products[1];
_ddBuyButton.enabled = YES;
_ddProductTitle.text = _ddProduct.localizedTitle;
_bundleProduct = products[0];
_bundleBuyButton.enabled = YES;
_bundleProductTitle.text = _bundleProduct.localizedTitle;
} else {
fvProductTitle.text = @"Full Version Product not found";
_ddProductTitle.text = @"Dirty Dozen Product not found";
_bundleProductTitle.text = @"Bundle Product not found";
}
products = response.invalidProductIdentifiers;
}
#pragma mark -
#pragma mark SKPaymentTransactionObserver
-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchased:
[self unlockFullVersion];
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
NSLog(@"Transaction Failed");
[[SKPaymentQueue defaultQueue]
finishTransaction:transaction];
break;
default:
break;
}
}
}
这是我的ShopViewController.h,用于查看我已设置的属性。
#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>
@interface ShopViewController : UIViewController <SKPaymentTransactionObserver, SKProductsRequestDelegate> {
}
@property (nonatomic) BOOL *isFullVersionAvailable;
// Store Kit
@property (strong, nonatomic) SKProduct *fvProduct;
@property (strong, nonatomic) SKProduct *ddProduct;
@property (strong, nonatomic) SKProduct *bundleProduct;
@property (strong, nonatomic) NSString *fvProductID;
@property (strong, nonatomic) NSString *ddProductID;
@property (strong, nonatomic) NSString *bundleProductID;
@property (strong, nonatomic) IBOutlet UIButton *fvBuyButton;
@property (strong, nonatomic) IBOutlet UIButton *ddBuyButton;
@property (strong, nonatomic) IBOutlet UIButton *bundleBuyButton;
@property (strong, nonatomic) IBOutlet UILabel *fvProductTitle;
@property (strong, nonatomic) IBOutlet UILabel *ddProductTitle;
@property (strong, nonatomic) IBOutlet UILabel *bundleProductTitle;
@property (strong, nonatomic) IBOutlet UITextView *fvProductDescription;
- (IBAction)buyFVProduct:(id)sender;
- (IBAction)buyDDProduct:(id)sender;
- (IBAction)buyBundleProduct:(id)sender;
- (void)getProductInfo:(UIViewController *)viewController;
@end
下面是我的ViewController.m,我的purchaseItem是用户按下以转换到商店页面并调用getProductInfo方法的内容。
- (IBAction)purchaseItem:(id)sender {
shopViewController.fvProductID = @"BurnsyBadges.FullVersion";
shopViewController.ddProductID = @"BurnsyBadges.DirtyDozen";
shopViewController.bundleProductID = @"BurnsyBadges.Bundle";
[shopViewController getProductInfo: self];
}
答案 0 :(得分:0)
回答我自己的问题。几个星期前我已经弄清楚了,并没有得到更新。但是为了让多个ViewControllers正确访问产品购买页面,我必须纠正一些事情。
要使一页工作,我需要将NavigationController添加到我的所有ViewControllers。