Reputation: 101
I've been through the forums and still can't seem to understand why my SKProductsRequestDelegate is never called. Thanks for your help.
- (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]);
}
Upvotes: 1
Views: 1059
Reputation: 11197
Try this;
- (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";
}
Upvotes: 0
Reputation: 37300
It's probably because you haven't set its delegate.
Make sure to add the delegate to your .h
@interface ViewController : UIViewController <SKProductsRequestDelegate>
Then set the delegate in your .m
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:self.productID]];
request.delegate = self;
Upvotes: 2