views:

793

answers:

1

I've wasted so much time on this and so I'm now begging for some help. 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 are 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. Thanks!

+2  A: 

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

You can set the release date to the distant future.

Rhythmic Fistman
Just submit it and immediately reject it. Don't want to set the date in the future and forget about it!
Stephen Darlington
Ah, ok. Good to know. Haven't tried it yet.
Rhythmic Fistman
Thanks. Unfortunately, Apple forgot to include this very important piece of information from their documentation, but I found that out after reading this helpful tutorial:http://troybrant.net/blog/2010/01/in-app-purchases-a-full-walkthrough/