user2720747
user2720747

Reputation: 101

SKProductsRequestDelegate never gets called

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

Answers (3)

Rashad
Rashad

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

Lyndsey Scott
Lyndsey Scott

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

Mustafa Ibrahim
Mustafa Ibrahim

Reputation: 1120

Just set request.delegate = self

Good luck

Upvotes: 0

Related Questions