54
votes

I'm trying to set up IAP but after making a call to retrieve the products using SKProductsRequest the SKProductsResponse array within my delegate has a count of 0. Here's my checklist:

  • Test product has been added to iTunes connect
  • The product's bundle id matches the app bundle id (and its not using a wildcard)
  • The product identifier set in the SKProductRequest matches the product created on iTunes connect
  • I've waited several hours since the product was created on iTunes connect
  • The provisioning profiles enable IAP
  • Followed all steps in various tutorial such as http://troybrant.net/blog/2010/01/in-app-purchases-a-full-walkthrough/ etc.
  • Have deleted app from device, relaunched Xcode, rebuilt etc. etc.

Any other suggestions as to why the fetched product count is zero?

I don't believe this will be a coding issue, but here it is anyway:

…

NSSet *productIdentifiers = [NSSet setWithObjects:@"redacted", nil];
self.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
self.productsRequest.delegate = self;
[self.productsRequest start];

…
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
    NSArray *products = response.products;
    NSLog(@"Product count: %d", [products count]);
    for (SKProduct *product in products)
    {
        NSLog(@"Product: %@ %@ %f", product.productIdentifier, product.localizedTitle, product.price.floatValue);
    }
}
15
Compare your code with the following code, that worked for me: github.com/wolf81/NewsHack/blob/master/FSProductStore.mWolfgang Schreurs
Thanks, but I don't believe it can be a code issues as there are only several lines so far. Adding them above anywayGruntcakes
I think you could just copy my class, change some identifiers and try to use it for purchase? Perhaps your issue is the environment you test with.Wolfgang Schreurs
The code I have posted is effectively already identical to the relevant portions of your code. What environmental factors need to be taken into consideration?Gruntcakes
Whether you connect to the production or test environment is one of the things you might have to keep in mind.Wolfgang Schreurs

15 Answers

40
votes

Check all 3 things in the list below
1) check your product identifiers - they must be exactly the same that you have in your code and in iTunes Connect -> My Apps -> YourAppName -> Features -> In-App Purchases enter image description here 2) iTunes Connect -> Agreements, Tax, and Banking -> Master Agreements -> Paid Applications-> Contact Info / Bank Info / Tax Info (should be filled)enter image description here 3) code to test it

class ViewController: UIViewController {

    var requestProd = SKProductsRequest()
    var products = [SKProduct]()

    override func viewDidLoad() {
        super.viewDidLoad()

        validateProductIdentifiers()
    }
}

extension ViewController: SKProductsRequestDelegate {

    func validateProductIdentifiers() {
        let productsRequest = SKProductsRequest(productIdentifiers: Set(["candy100", "someOtherProductId"]))

        // Keep a strong reference to the request.
        self.requestProd = productsRequest;
        productsRequest.delegate = self
        productsRequest.start()
    }

    // SKProductsRequestDelegate protocol method
    public func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {

        self.products = response.products

        for invalidIdentifier in response.invalidProductIdentifiers {
            print(invalidIdentifier)
        }

    }
}

14
votes

I was facing the same problem, Solved it by sending just the IAP Product name rather than my bundle id before the product name. Here is the example :

works SKProductsRequest *productRequest = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:@"my_product"]];

rather than

doesn't work SKProductsRequest *productRequest = [[SKProductsRequest alloc]initWithProductIdentifiers:[NSSet setWithObject:@"com.my_site.my_app.my_product"]];

14
votes

Make sure you have In-App Purchase turned on in the Capabilities section. If you don't, SKProductsRequest will return 0 products.

13
votes

I had the same issue...

I simply change my bundle identifier which does not match with an iTunes bundle identifier.

And my app runs well :)

7
votes

In the off chance that you've overlooked this, the product identifier match is case sensitive.

So, if you've created a product on Apple with an identifier of say

com.yourcompany.product1

and you call the product request with a product identifier of

com.yourcompany.Product1

Your list will be returned with zero products.

This kept me busy for a while :-)

ps: On a separate project, I found SKProductsRequest only started returning products after a restart. So, if all else fails, try restarting your Mac.

3
votes

IN swift 5, I am facing the same problem getting Skproducts count 0. I solved this Goto enter image description hereiTunes Connect -> Agreements and Tax if status is New there then there should be term view button besides status click it fill the complete form and then the paid apps will be shown status active and Skproducts counts would be visible in xcode console.

2
votes

Some times there are very carrying solutions to these types of problems. After doing some research, I found that it sometimes helps to delete the app and then install it again(In-App Purchase, SKProductsRequest returning 0 - Products still in Review) Also what version of iOS are you using?

1
votes

Please also whether you have set price of the product in iTunesConnect or not.I missed that and products were zero.Wasted my whole day to figure out this.

1
votes

Let's go to iOS's Settings > iTunes & App Stores and Log out

Hope this help you, I don't know why :D

0
votes

Also, keep in mind that agreeing to the Paid Applications cotract is not enough. You also have to fill out the contact, bank and tax information for that agreemant specifically, for it to be considered done.

0
votes

After digging a lot, following steps solved my issue of getting 0 products for SKProductsRequest.

Go to Settings > Sign in to your iPhone on your iOS device. If you're already logged in with your original Apple ID, tap on it and choose Sign Out. Then simply sign in with the credentials for the sandbox tester you created in iTunes Connect.

0
votes

I'm getting an empty SKProductsResponse.products array on some macOS 10.14 systems while others work just fine and return the valid list of current IAPs for my app.

Same app, identical code.
User logged into the same App Store account on both machines.

That's just plain weird.

0
votes

In my case that was a bug. In simulator all product identifiers fails and was marked as invalid. In real device all product request successfully fetched a product.

TvOS 4K

0
votes

I had this issue even after accepting the Tax and Agreements Section in App Store. I use to change my Apps bundle Id many times(for sending builds to testers), I suspected this could be the issue. So I fixed this issue as follows.
Go to Target -> BuildSettings -> Search for "Product Bundle Identifier". It should be $(PRODUCT_BUNDLE_IDENTIFIER).
After updating this go to General -> Bundle Identifier. Enter your proper bundle Id which has In-App purchase capability. After doing this changes I'm able to list the products

0
votes

Swift 5 xcode 12.4 simulator returned zero products.

Using a physical device returned products properly