Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get In-App Purchase to work

Ok I am tearing my hair out over this. I am developing an app that will be free (with ads and some locked-down functionality). An in-app purchase will remove the ads and provide full functionality.

So I set up a SKProductsRequest passing it my product id (com.mydomain.Myapp.fullversion) and execute 'start'. This does not fail and goes on to call productsRequest:didReceiveResponse:, where an NSLog shows that response.products.count equals zero - so problem!

So, stupid question first.

Q1. When running my app via Xcode on my test device, does the test device need to have a connection to the Internet (e.g. wireless ON) or is it sufficient that the Mac which is running Xcode has an Internet connection? (Answered: You need a connection on the test device).

Q2.How do I get this to work?

I have checked all of the following:

Have you enabled In-App Purchases for your App ID?:
In the Provisioning Portal under App IDs I have 'bundle_seed_id.com.mydomain.Myapp' and 'In-App Purchase' is enabled.

Have you checked Cleared for Sale for your product?:
In iTunes Connect I have created my in-app purchase 'com.mydomain.Myapp.fullversion' and it is cleared for sale.

Does your project’s .plist Bundle ID match your App ID?:
Yes it does, it is set to 'com.mydomain.Myapp'.

Have you generated and installed a new provisioning profile for the new App ID?:
Yes I have created and installed a PP for 'com.mydomain.Myapp'.

Have you configured your project to code sign using this new provisioning profile?:
I only have entries under 'Code Signing Identity' (and not CS Entitlements, CS Resource Rules Path and Other CS Flags). It has been set by Automatic Profile Selector > IPhone Developer and matches myself for Myapp, and is set for Debug > Any SDK and Release > Any iOS SDK.

Are you using the full product ID when when making an SKProductRequest?:
Yes, I am using 'com.mydomain.Myapp.fullversion'.

Have you waited several hours since adding your product to iTunes Connect?:
Yes, I have waited 24 hours.

Are your bank details active on iTunes Connect?:
Yes they are.

Have you tried deleting the app from your device and reinstalling?:
Many times.

An observation here: On the test device, I am not logged in to 'iTunes & App Stores' and when I run the app from Xcode on the test device it has not asked me to log in (I have a test user set up in iTunes Connect and ready to use). So my app runs, calls start on SKProductRequest but never prompts me to log in to 'iTunes & App Stores'.

Many thanks in advance. I hope someone can help me to get In-App purchases working. Byron.

Update 1: Here is some code though I am not sure how much that will help, As I said above it is failing at productsRequest:didReceiveResponse: by not returning any products.

First I call:

[[MyappIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products)
     {
         if (success)
         {
             NSLog(@"SUCCESS - WE HAVE PRODUCTS");

             _products = products;

             NSLog(@"_products.count = %d", _products.count);
         }
         else
         {
             if(products == nil)
             {
                 NSLog(@"FAILED - WE HAVE NO PRODUCTS");
             }
         }
     }];

The code for that looks like:

- (void)requestProductsWithCompletionHandler:(RequestProductsCompletionHandler)completionHandler
{
    _completionHandler = [completionHandler copy];

    NSLog(@"IAPHelper, requestProductsWithCompletionHandler{}, _productIdentifiers = %@", [_productIdentifiers anyObject]);

    _productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:_productIdentifiers];
    _productsRequest.delegate = self;
    [_productsRequest start];

}

The 'start' does not fail and goes on to call productsRequest:didReceiveResponse:

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response

{

NSLog(@"Loading list of products...");

NSLog(@"iAPHelper, productRequest:didRecieveResponse{}, Products count = %d", response.products.count);

And as soon as you come into this function it has failed as response.products.count equals zero.

I have just added the following debug code to productRequest:didRecieveResponse{}

for (NSString *invalidProductId in response.invalidProductIdentifiers)
{
    NSLog(@"Invalid product id: %@" , invalidProductId);
}

And it states that 'com.mydomain.Myapp.fullversion' is invalid.

Update 2: This is beyond a joke now - still not working!

I have followed http://developer.apple.com/library/ios/#technotes/tn2259/_index.html exactly. I thought that the problem may have been that when creating my in-app purchase I had uploaded a screenshot - but I rectified that by deleting the in-app purchase, re-creating it ensuring that it is in state of 'Waiting for Screenshot' as per documentation. I have now waited over 12 hours for the re-created in-app purchase to filter through Apple's servers. I deleted the app from my test device. Checked that I am logged out of the store on the test device. Re-started my test device. Performed a 'Clean' in Xcode and re-started Xcode. Ran the app from Xcode and guess what? Invalid product identifier!!!! Help, please anyone, I am losing my mind!!!!!

like image 847
Byron Cox Avatar asked Feb 05 '13 20:02

Byron Cox


2 Answers

PROBLEM SOLVED

After raising a TSI the Apple representative finally found my problem.

Looking at my app in iTunes Connect it states that it has a Bundle ID of 'Myapp'. Whereas the App ID in the Provisioning Portal which had In-App Purchase enabled was 'bundle_seed_id.com.mydomain.Myapp'. What was not obvious, or at least to me, is that this App ID is comprised of a Bundle ID that has to match the Bundle ID of the app in iTunes Connect.

The first App ID I ever created in the Provisioning Portal was a wild-card one. When you go through the process of creating a new application, it wants you to enter a Bundle ID that you select from a drop-down list that is populated from the App IDs in the Provisioning Portal. If you select a Bundle ID that has a wild-card it then asks for a Bundle ID Suffix, which is where I would have entered 'Myapp' and then 'Myapp' ends up becoming your Bundle ID. A little odd as i thought that was just a suffix.

Later (some months later) when I decided that I would like to implement In-App Purchase I would have discovered that wild-card App IDs cannot be used with the Push Notifications or for In-App Purchase. So I would have then created a new App ID in the Provisioning Portal, following the prompts which state that "The recommended practice is to use a reverse-domain name style string for the Bundle Identifier portion of the App ID" - hence I entered 'com.mydomain.Myapp'. I was unaware that the Bundle ID I was creating for the App ID had to match the Bundle ID of the application created previously in iTunes Connect.

I have now created a new App ID of 'bundle_seed_id.Myapp' in the Provisioning Portal and voila, my Product ID of 'com.mydomain.Myapp.fullversion' is no longer invalid and this now appears to be working.

like image 74
Byron Cox Avatar answered Sep 18 '22 22:09

Byron Cox


A1. you need a connection on your test device

A2. post some code

like image 42
Joris Weimar Avatar answered Sep 20 '22 22:09

Joris Weimar