Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone In App Purchase - response.products are still empty?

Basically, I've tried to set up in app purchases on a test app before I implement them into a proper app that my company is working on. I've read the Store kit pdf and other snippets about a 1000 times, but the products are still being returned as empty. Here's exactly what I've done so far:

Setup test app and In App Purchase test items
I created a new app id for 'Test App One' on my company's developer portal in the iPhone Dev Centre. I made sure that the prefix was com.mycompany.testappone to ensure that in app purchases could be configured. Staying in the App IDs section, I configured in app purchases by ticking the 'Enable In App Purchase' option.

I created 'Test App One' in iTunes Connect and completed the usual procedure but selected 'upload binary later' and didn't submit for review as the app does nothing. Surely we don't have to submit the app to review for this to work?! I then clicked on manage in app purchases and created a new one with product id 'test1' and approved it so that it is cleared for sale.

Code
I set up a new project in XCode called TestAppOne and here are the only 2 classes I am using for now:

TestAppOneAppDelegate.h:

#import <UIKit/UIKit.h>
#import <StoreKit/StoreKit.h>  

@interface TestAppOneAppDelegate : NSObject <UIApplicationDelegate, SKRequestDelegate, SKProductsRequestDelegate> {
    UIWindow *window;
}

TestAppOneDelegate.m:

#import "TestAppOneAppDelegate.h"

static NSString *kMyFeatureIdentifier1 = @"com.mycompany.testappone.test1";

@implementation TestAppOneAppDelegate
@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
 if([SKPaymentQueue canMakePayments]) {
  NSLog(@"IN-APP:can make payments");
 }
 else {
  NSLog(@"IN-APP:can't make payments");
 }

 [self requestProductData];
 [window makeKeyAndVisible]; 
}

- (void)requestProductData {
 NSLog(@"IN-APP:requestProductData");
 SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject:kMyFeatureIdentifier1]];
 request.delegate = self; 
 [request start];
 NSLog(@"IN-APP:requestProductData END");  
} 

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
 NSLog(@"IN-APP:productsRequest");
 NSArray *myProduct = response.products;
 NSLog(@"IN-APP:array count: %i", [myProduct count]);
 [request autorelease];
 NSLog(@"IN-APP:productsRequest END"); 
}

- (void)dealloc {
    [window release];
    [super dealloc];
}

@end

Testing on the device
I created a sandbox test account and logged out of my iTunes account on the iPhone, but didn't log in with the test account as the documentation tells us to not do this until we are prompted at the purchasing stage. I then build the app and here is the log I'm getting:

IN-APP:can make payments
IN-APP:requestProductData
IN-APP:requestProductData END
IN-APP:productsRequest
IN-APP:array count: 0
IN-APP:productsRequest END

Can anyone please tell me if I have left any stages out or if there is anything that I'm doing wrong. Unfortunately there doesn't seem to be any example apps made by Apple.

like image 729
user218485 Avatar asked Jan 26 '10 11:01

user218485


People also ask

Why are in-app purchases not working on iPhone?

Make sure you're signed in with the same Apple ID that you used to make the purchase. Make sure in-app purchases are allowed on your device. Restart your device: Restart your iPhone.

Why are my in-app purchases not working?

If you haven't received an in-app item you bought, try closing and restarting the app or game you're using. Tap Apps or Manage applications (depending on your device, this may be different). Tap the app you used to make your in-app purchase.

How long does it take Apple to review in-app purchases?

Review status On average, 90% of submissions are reviewed in less than 24 hours. You'll be notified by email of status changes. You can also check the review status of your submission in the My Apps section of App Store Connect or on the App Store Connect app for iPhone and iPad.


8 Answers

Another important step that is often overlooked is you need to make sure you have an iOS Paid Applications Contract setup which is located under the "Contracts, Tax, and Banking" section of iTunes connect. First you have to click on the request button, then you have to click on the 3 Set Up buttons (Contact Info, Bank Info, Tax Info)

like image 132
AlBeebe Avatar answered Oct 05 '22 18:10

AlBeebe


Actually I do think you have to submit the binary for this to work.

You can set the release date to the distant future.

like image 27
Rhythmic Fistman Avatar answered Oct 05 '22 18:10

Rhythmic Fistman


Check whether there are invalid product id's.

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

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

If there are invalid product ids visit http://troybrant.net/blog/2010/01/invalid-product-ids/

It is a very comprehensive check-list for this problem.

Edit: (13/11/20) Site seems to be down. I'm not sure whether it is a permanent problem but you can see the page from archive.org: https://web.archive.org/web/20200212001158/http://troybrant.net/blog/2010/01/invalid-product-ids/

like image 34
alpere Avatar answered Oct 05 '22 19:10

alpere


Check if your Bundle Identifier (e.g. com.company.appname) in XCode matches the one in iTunes Connect.

You do not have to submit the binary for it to work.

like image 21
dcRay Avatar answered Oct 05 '22 18:10

dcRay


Just delete the application on your device, and start it again from XCode. It fixed the problem for me.

No need to upload the binary, or wait for hours after creating the in-app purchase in iTunes Connect.

like image 23
haddock Avatar answered Oct 05 '22 17:10

haddock


Thanks to alpere's answer I found out that I used the wrong product ID. It was not as I thought de.company.appname.PROFESSIONAL_LICENSE. Just using PROFESSIONAL_LICENSE in my case (without leading bundle id stuff) works :)

like image 37
HeyMan Avatar answered Oct 05 '22 18:10

HeyMan


No need to upload binary for Sandbox testing of InAppPurchase. You just have to add InAppPurchase item in iTunesConnect and put it in "Ready to submit"(must) state only. If you submit it for review it will always give ou response.product empty.

like image 39
stack Avatar answered Oct 05 '22 17:10

stack


Try to add a Free Subscription product. If it appears on the response then there is nothing wrong in your code. Since Free Subscription is the only type that doesn't require Agreements, Tax, and Banking and if it appears and the other types don't then it is a issue related to your contract.

like image 23
Paulo Henrique Nonaka Avatar answered Oct 05 '22 17:10

Paulo Henrique Nonaka