我遵循了本教程http://www.techotopia.com/index.php/An_iOS_7_In-App_Purchase_Tutorial
- (IBAction)btnBuy:(id)sender {
NSLog(@"product name: %@", self.product.price);
SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:self.product];
payment.quantity = 1;
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
-(void) getProductInfo: (FirstViewController *) viewController {
NSLog(@"Enter get Product Info method");
self.fvController = viewController;
//getting the product information
if ([SKPaymentQueue canMakePayments]) {
SKProductsRequest *request =[[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:self.productID]];
request.delegate = self;
[request start];
} else {
NSLog(@"Product request failed");
self.tvProductDes.text = @"Please enable In App Purchase in Settings";
}
}
#pragma mark -
#pragma mark SKProductsRequestDelegate
-(void) productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSLog(@"Enter Products Request method");
NSArray *products = response.products;
if (products.count != 0)
{
self.product = products[0];
NSLog(@"%@", self.product.localizedTitle);
btnBuy.enabled = YES;
//_productTitle.text = _product.localizedTitle;
tvProductDes.text = product.localizedDescription;
} else {
NSLog(@"Product not found");
}
products = response.invalidProductIdentifiers;
for (SKProduct *p in products)
{
NSLog(@"Product not found: %@", p);
}
}
观察者设置在另一个视图控制器中:
self.purchaseController = [self.storyboard instantiateViewControllerWithIdentifier:@"purchaseVC"];
[[SKPaymentQueue defaultQueue] addTransactionObserver: self.purchaseController];
在上面的代码中,请求产品正常工作。但是,在调用btnBuy Action时,应用程序中不会返回任何响应。
有谁知道什么是错的?我认为这是SKMutablePayment。
我的产品已在iTunes上,并已准备好提交状态。任何帮助将不胜感激。