在'SKProductsRequest'类型的对象上找不到的属性产品

时间:2014-04-01 11:20:53

标签: objective-c cocos2d-iphone in-app-purchase storekit

我正在尝试关注此tutorial,但是在行中:

int count = [response.products count];

我收到了这个错误:

Property products not found on object of type 'SKProductsRequest *'

这是我的代码:

-(id)init
{

 if (self = [super init]) {

 NSLog(@"game store loaded");
 if ([SKPaymentQueue canMakePayments])
 {
 NSLog(@"can make payments");
 SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:@"teste2"]];
 //productsRequest.delegate = self;
 [productsRequest start];

 //start Buying/buy button
 SKPayment *payment = [SKPayment paymentWithProductIdentifier:@"teste2"];
 [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
 [[SKPaymentQueue defaultQueue] addPayment:payment];
 }
 else {
 NSLog(@"Please enable In App Purchase in Settings");
 }
 }



 return self;

}


-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse: (SKProductsRequest *)response {
 SKProduct *validProduct = nil;
 int count = [response.products count];
 if (count > 0) {
 NSLog(@"%d products available", count);
 validProduct = [response.products objectAtIndex:0];
 } else if (!validProduct) {
 NSLog(@"No products available");
 }

}

-(void)paymentQueue:(SKProductQueue *)queue updatedTransactions:(NSArray *)transactions {
 for (SKPaymentTransaction *transaction in transactions) {
 switch (transaction.transactionState) {
 case SKPaymentTransactionStatePurchasing:
 //avisa usuario que o produto esta sendo comprado
 break;
 case SKPaymentTransactionStatePurchased:
 //faz alguma coisa quando o produto for comprado

 [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
 break;
 case SKPaymentTransactionStateRestored:
 [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
 break;
 case SKPaymentTransactionStateFailed:
 if (transaction.error.code != SKErrorPaymentCancelled) {
 NSLog(@"An Error Encoutered");
 }
 [[SKPaymentQueue defaultQueue] finishTransaction:transaction];

 default:
 break;
 }

 }

}

@end

1 个答案:

答案 0 :(得分:2)

您的方法签名错误,应该是:

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response

(您已将响应类指定为SKProductsRequest,如果它应为SKProductsResponse)。