My main problem when trying to test inapp purchase was the dreadful and hard to debug 'Invalid product id' state of my SKProductsRequest object.
So i wrote a little helper (mainly for myself), to guide along the hard path to a successful inapp purchase.
First, i found VERY valuable informations on these links:
- http://yaus.eu/anmi
- http://yaus.eu/fwmj (IMPORTANT, MUST BE READ !)
- http://yaus.eu/aqmk
- http://yaus.eu/ykml (this one contains code samples)
- http://yaus.eu/lnmm (Apple tech note)
As a reminder the very first step of an inapp purchase is to 'register' the ids of the products (productId) you want to use in your app.
This is done with code like (see: http://yaus.eu/ykml)
...
NSSet *productIdentifiers = [NSSet setWithObject:@"my.complete.product.id" ];
productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start];
...
You register your products (be careful with the name, it must be complete !), and send a request to the appstore.
Provided that:
- you're not connected with any itunes account,
- you're running the app with XCode (mandatory, connexion to the sandbox is only via XCode),
this first step will attempt to connect to the appstore and check the available products for you application id.
From what i've read (a lot!), about 90% of errors in inapp purchases can be detected at this very point.
On the callback method (productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
), if there's no products in the response (response.products)
-> THERE'S NO NEED TO GO FURTHER: YOU'RE OUT !
Refer to http://yaus.eu/fwmj to see all possible causes of an invalid product id.
In the present case, my errors were the following...
1 - I sent a binary of the app and then rejected it
DON'T EVER PUBLISH YOUR BINARY!
Inapp testing MUST be done without sending the binary of your app. If any reject occurs (app or developper), the whole process is crashed.
2 - My provisioning profile was not configured to use in app. Yeah. Dumb. But not so obvious.
CREATE A SPECIFIC CERTIFICATE ONLY FOR YOUR APP !
Don't forget to fully qualify the name of the app, no wildcards in it.
3 - I approved my app purchase.
DON'T !
4 - i connected with the test account OUTSIDE Xcode
NEVER CONNECT WITH THE ITUNES-CONNECT DEV/TEST ACCOUNT OUTSIDE OF XCODE !
The fact of running in XCode redirects automatically to the sandbox. On the opposite, when not running in XCode, if you use your test account, it will be considered as a production account.
One final point, when you create an app and you don't submit a binary, the bundle id of the app is not set.
No to worry about.
The creation of a valid provisionning profile in the portal is autodetected by itunes connect and when managing the new inapp purchase, you will be asked for a bundle id in a list of 'inapp enabled' certificates.