我经历过论坛,似乎仍然无法理解为什么我的SKProductsRequestDelegate从未被调用过。谢谢你的帮助。
- (void)getProductID:(PortViewController *)viewController {
_homeViewController = viewController;
//retrieve product info from iTunes connect;
if ([SKPaymentQueue canMakePayments]) {
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:self.productID]];
//NSLog(@"Description: %@", request.);
NSLog(@"ProductID: %@", self.productID);
NSLog(@"Title: %@", self.title);
[request start];
} else
_productDescription.text = @"Please enable in app purchase in your settings";
}
#pragma mark _
#pragma mark SKProductsRequestDelegate
-(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSArray *products = response.products;
NSLog(@"Recieved Product Response %@",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);
}
}
- (void)requestDidFinish:(SKRequest *)request {
NSLog(@"purchase request finished");
}
- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {
NSLog(@"%@", [error description]);
}
答案 0 :(得分:2)
可能是因为你没有设置它的代表。
确保将代理人添加到.h
@interface ViewController : UIViewController <SKProductsRequestDelegate>
然后在.m
中设置代理SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:self.productID]];
request.delegate = self;
答案 1 :(得分:0)
只需设置request.delegate = self
答案 2 :(得分:0)
试试这个;
- (void)getProductID:(PortViewController *)viewController {
_homeViewController = viewController;
//retrieve product info from iTunes connect;
if ([SKPaymentQueue canMakePayments]) {
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:self.productID]];
request.delegate = self
NSLog(@"ProductID: %@", self.productID);
NSLog(@"Title: %@", self.title);
[request start];
} else
_productDescription.text = @"Please enable in app purchase in your settings";
}