iPhone: Cannot test InAppPurchase in sandbox after it is approved - iphone

I have a free iPhone App which uses in app purchase. I tested my first InAppPurchase with sandbox environment and it worked fine. After the InAppPurchase was approved and worked fine in App store, I added several new InAppPurchases in iTunes Connect and tried to test them in the sandbox environment. However I could not find these new InAppPurchases in my app.
The following is the code I uses to get InAppPurchase products:
//....
SKProductsRequest *prodRequest= [[SKProductsRequest alloc] initWithProductIdentifiers:
[NSSet setWithObject: prod]];
prodRequest.delegate = self;
[prodRequest start];
//....
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
int count = [response.products count];
NSLog(#"number of products:%d",count);
for (int i=0; i < count; i++) {
SKProduct* product = [response.products objectAtIndex:i];
NSLog(#"product %d:id=%# title=%# desc=%# price=%#", i, product.productIdentifier, product.localizedTitle,
product.localizedDescription,
product.price);
}
}
If I use the old InAppPurchase product id I can get it, but if I use any newly created product id I got count==0.
From what I saw, I guess may app may not be running in the sandbox environment after my first InAppPurchase was approved, but this is just a guess, because I don't know how to check if my app is in sandbox mode or not.
I searched Internet about this issue and tried the following:
1. created a new version of my app, uploaded it to iTunes connect, and rejected the binary. no use
2. deleted all my provisioning profiles and created new ones. no use
3. created an app id for my app in developer provisioning portal and created provisioning profile for that id and used it in Xcode. no use
My Xcode version was 3.2.5. I upgraded it to 4 but this did not fix the problem.
I am wondering if any one else has seen this issue and found a solution. Thanks.

OK I came across this post and got some hint:
Product Identifiers Are Valid On One Phone But Not Another
I just deleted the app from my iPod Touch, did not reboot, then tried to run my app from Xcode again, and it worked. I guess there was some states saved together with the app which determines whether to use sandbox environment for InAppPurchase or not. Although I could run my newly compiled binary without deleting the old app, I could not get rid of some old state which caused the app not running in the sandbox environment. That is what caused the problem. The solution is to delete the old app from the device before running newly compiled binary.

Related

In-App Purchase doesn't work

I want to add in-app purchases to my app, but I can't make it work. I'm using MKStoreKit 4.2.
Here is the buying code:
- (IBAction)onPayButtonPressed:(id)sender {
[[MKStoreManager sharedManager] buyFeature:#"com.flowrower.TestApp.0.99.item"
onComplete:^(NSString* purchasedFeature, NSData* receiptData)
{
NSLog(#"Purchased: %#", purchasedFeature);
}
onCancelled:^
{
NSLog(#"Cancelled");
}];
NSLog (#"END");
}
In output I'm always getting "END" only. So buyFeature doesn't work at all.
Testing on iPhone 4S with iOS 6.0.
Using Provision Profile with In-App Purchases support.
There is Product ID "com.flowrower.TestApp.0.99.item" in iTunes Connect with status "Ready to submit"
This product is consumble and I have added it to MKSoreKitConfigs.plist
Everything's OK with Contacts, Bank and Taxes in iTunes Connect
Logged off from iTunes and App Store on my device.
Getting this message at app start: "NSUbiquitousKeyValueStore error: user.TestApp has no valid com.apple.developer.ubiquity-kvstore-identifier entitlement". I don't know is it related or not.
if its not approved, you need to test in the sandbox. I don't know MKStoreKit but I think you need an adhoc certificate!?
The problem was with iOS 6. 12 days ago new version of MKStoreKit released and it work like a charm in iOS 6. Thanks guys.

SFProductsRequest always returning zero

I'm trying to implement in app purchases in a free application.
I have created a productd id "test1" within the in app purchases manager in itunes connect portal.
When I make the product request in the following way:
- (id)init {
NSSet *productIdentifiers = [NSSet setWithObjects:
#"test1",
nil];
if ((self = [self initWithProductIdentifiers:productIdentifiers])) {
}
return self;
}
- (id)initWithProductIdentifiers:(NSSet *)productIdentifiers
{
if ((self = [super init]))
{
// Store product identifiers
_productIdentifiers = [productIdentifiers retain];
// Check for previously purchased products
NSMutableSet * purchasedProducts = [NSMutableSet set];
for (NSString * productIdentifier in _productIdentifiers)
{
BOOL productPurchased = [[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier];
if (productPurchased)
{
[purchasedProducts addObject:productIdentifier];
NSLog(#"Previously purchased: %#", productIdentifier);
}
NSLog(#"Not purchased: %#", productIdentifier);
}
self.purchasedProducts = purchasedProducts;
}
return self;
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
NSLog(#"Received products results...");
self.products = response.products;
self.request = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:kProductsLoadedNotification object:_products];
NSLog(#"%d",[self.products count]);
NSEnumerator *e = [self.products objectEnumerator];
id object;
while(object=[e nextObject])
{
NSLog(#"item");
NSLog(#"%s",(char*)object);
}
}
- (void)requestProducts {
self.request = [[[SKProductsRequest alloc] initWithProductIdentifiers:_productIdentifiers] autorelease];
_request.delegate = self;
[_request start];
}
The response is always 0. I don't understand what am I doing wrong. This code came from a tutorial. The documentation regarding in app purchases tend to be quite confusing and the whole process in itunes connect doesnt give me confidence.
I thought the application needed to be online for sale for in app purchases to be working. However, I decided not to included in app purchases, but let the in app purchase in itunes connect for review. During the review process, the application was rejected because it should be working with the in app purchases for testing.
But how do I test in app purchases if the product listing comes always at zero?
If someone with more experience could give me an advice on this, since i'm already getting crazy with it!
Thanks,
With my best regards,
Nuno
The most coherent solution I found to this problem was this checklist. It should be wide spreaded in order to avoid anyone passing by the same problem which is really time consuming and desperating:
Have you enabled In-App Purchases for your App ID?
Have you checked Cleared for Sale for your product?
Have you submitted (and optionally rejected) your application binary?
Does your project’s .plist Bundle ID match your App ID?
Have you generated and installed a new provisioning profile for the new App ID?
Have you configured your project to code sign using this new provisioning profile?
Are you building for iPhone OS 3.0 or above?
Are you using the full product ID when when making an SKProductRequest?
Have you waited several hours since adding your product to iTunes Connect?
Are your bank details active on iTunes Connect? (via Mark)
Have you tried deleting the app from your device and reinstalling? (via Hector, S3B, Alex O, Joe, and Alberto)
Is your device jailbroken? If so, you need to revert the jailbreak for IAP to work. (via oh my god, Roman, and xfze)
Are you logged out from real iTunes account?
Have you tried restarting device?
Are you on Device? (Will not work on Simulator)
Credits go to Troy Brant
Have a look here, that answered all of my questions (and the framework is simple to use, too :-):
http://blog.mugunthkumar.com/coding/iphone-tutorial-%E2%80%93-in-app-purchases/
But I have to say the whole in-app purchase thing is a PITA - my app just got released, and of course I downloaded it and checked the in-app purchase screen. Guess what, it came up completely empty!
After some reading up it seems that even if all is accepted and ready for sale, the in-app purchase products still need a while to become available online - after 3 hours it finally worked ...
EDIT:
You need to create the in-app purchase for your app and set it to clear for sale in itunes connect. You do not need to upload a screenshot yet or have it already reviewed in order to be able to test it in development mode.
How did you name the purchase in itunes connect? Normally you should use a com.companyname.productname.purchasename name, and the name you request from your app ha to be exactly the same.

In App Purchase - can get product info but can't connect to itunes for purchase

I'm trying to make "In App Purchase " works in my iphone app.
I created some products and a few test accounts in itunes connect.
I have no problem to retreive the products data (prices etc..) but when I try to make a payment
- I am asked to log in
- I use a test account
-> the transaction always fail with the following error :
failedTransaction with error : Error Domain=SKErrorDomain Code=2 "Connexion à l’iTunes Store impossible" UserInfo=0x65d02a0 {NSLocalizedDescription=Connexion à l’iTunes Store impossible}
I tried with several products and test account (even in other stores like us) but I still get the same error...
NB : I think it worked fine the first time I tried but never still
Any idea will be welcome !
Thanks
For me, I just scoured my code until I found my mistake. I was so certain everything was fine, but it was not. When I requested product information from the store, I used the correct Product Identifier:
self.productRequest= [[[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: #"com.popculturesoft.RC_vCar.fullVersion"]] autorelease];
However, when I went to create the payment, I used the incorrect Product Identifier:
SKPayment *payment = [SKPayment paymentWithProductIdentifier:#"com.popculturesoft.RC_vCar_Lite.fullVerson"];
Using the product Identifier for the payment is not the correct way to do it, although it allows you to do it. It is better to use an SKProduct object. (I had set the fullProduct property earlier in the code:
SKPayment *payment = [SKPayment paymentWithProduct:self.fullProduct];
I was absolutely certain that the store was down, and that was the problem. But the next day I decided to start from the beginning of the process, as described in http://developer.apple.com/library/ios/#technotes/tn2259/_index.html. This is when I found that my incorrect Product Identifier was the problem.
Check out this thread. It seems to be a problem with the Sandbox. Lot's of people having this issue-
iPhone storekit sandbox stopped working
I had the same symptoms and in my case the problem was that I had a test user account with the same name as a real Apple ID account. I resolved the problem by creating a different test user account.

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.
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)
Actually I do think you have to submit the binary for this to work.
You can set the release date to the distant future.
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/
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.
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.
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 :)
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.
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.
In my case the reason was hosting of content by Apple turned on by mistake. The product was available only when I turned it off
In my case (MacOS) I was creating a test application (with the same bundle ID of main application). SKFetchRequest started returning product Ids for test application only after I set Bundle Name (Binary name) the same as in original application.

iPhone Store Kit returning invalid product ID errors

I am trying to test In App Purchases on my iPhone and running into a problem where the product IDs I request information for end up being returned to me as invalid product IDs in the "didRecieveResponse" method.
I have:
Created an in store product associated with this app. It's bundle ID matches everything else. It has been cleared for sale and approved by the developer.
Made sure my new provisioning profile has in store app purchases enabled and it has the full app name: "com.domain.appname"
Made sure this is the provisioning profile being used to sign the app to my iPhone.
Made sure that "com.domain.appname" is the app ID used to build the provisioning profile.
Made sure that "com.domain.appname" is used in my plist file as the bundle identifier.
Everything seems to be in place, however I still get my products returned to me as invalid IDs.
This is the code I am using:
- (void)requestProductData {
SKProductRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers: [NSSet setWithObject: #"com.domain.appname.productid"]];
request.delegate = self;
[request start];
}
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
NSArray *myProducts = response.products;
NSArray *myInvalidProducts = response.invalidProductIdentifiers;
for(int i = 1; i < myInvalidProducts.count; ++i)
{
std::cout <<"invalid product id = " << [[myInvalidProducts objectAtIndex:i] UTF8String] << std::endl;
}
for(int i = 0; i < myProducts.count; ++i)
{
SKProduct * myProduct = [myProducts objectAtIndex:i];
std::cout << "Product Info:" << std::endl;
std::cout << "\tlocalizedTitle = " << [[myProduct localizedTitle] UTF8String] << std::endl;
std::cout << "\tlocalizedDescription = " << [[myProduct localizedDescription] UTF8String] << std::endl;
std::cout << "\tproductIdentifier = " << [[myProduct productIdentifier] UTF8String] << std::endl;
std::cout << "\tprice = " << [[myProduct price] doubleValue] << std::endl;
std::cout << "\tpriceLocale = " << [myProduct priceLocale] << std::endl;
}
[request autorelease];
}
All my product IDs show up in the invalid printouts and none of them show up in the "Product Info:" printouts.
Any suggestions would be greatly appreciated...
P.S. Yes, this is built as Objective-c/c++.
I tried everything suggested in the Apple forums and here, and still couldn't get it to work. Found the solution - your app needs to be transferred by Xcode for the sandbox to be enabled.
Obvious, right? Well, if you are working with an update to an existing account, the device will still treat it as an App Store-installed app.
Delete it, then transfer it again. It should work now :)
Deleting the app on the testing iPhone and reinstalling it worked. Also I had also waited 8 hours since submitting the in-app purchase item.
Please Go through the steps below:
Log in to iTunes connect using your developer account (https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wo/).
Go to the Tab - "Contracts, Tax, and Banking"
Check the Request Contracts and Contracts in Process sections.
Check out the "iOS Paid Applications" and there Contact Info , Bank Info and Tax Info are need to Set up.
When "iOS Paid Applications" cell will move to Contracts in Effect section, I will be able to use Products for in App Purchase.
Please go through the link below for more information:
http://developer.apple.com/library/ios/#technotes/tn2259/_index.html
Please note that when iPhone is jailbroken the AppSync packet breaks in-app-purchasing testing completely.
AppSync is installed with Install0us as a dependency.
You don't have to restore iOS completely, just uninstall AppSync in Cydia to test in-app-purchases with success.
All tips from all forums, tutorials and comments about fixind 'invalid product' did not work for me until I removed AppSync.
I've been having a similar problem with a new app (v1.0 not yet released in store) that I was trying to add in app purchases too. I set everything up, added products, etc. and my products ALWAYS came back as invalid when I did an SKProductsRequest.
I was about to give up on the entire process, when I saw a tangentially-related post on the Apple developer forums. It suggested deleting the app from the test device and and doing a fresh build+install. That did the trick.
Just to be sure, I tried it on another device that was giving me the same trouble, and it fixed it there too.
It's just a guess, but I think that if the device has a build on it that was made with a provisioning profile that was created BEFORE you add IAP, you need to remove that build and put on a fresh one using the IAP profile. (That is, simply replacing the app in place won't do the trick.)
if nothing wrong in your code,
sometime it has return invalid productId
just because, you may need a time over 10 hour for your changing info. taking effect.
Or, the productId invalid because something wrong are remained on your device, so you can try once more with delete your app and build it again.
with my experience,
hope it will helps.
OK, so after doing everything I could possibly think of and reading every forum out there, here is what worked:
Redo EVERYHING.
Remove ALL your provisioning profiles from the Xcode Organizer.
Close Xcode.
Create a New App ID.
Create a new Provisioning profile with the new App ID.
Create a new Distribution Provisioning profile with the new App ID.
Create a new App in iTunes Connect
Start Xcode, install your two new provisioning profiles. Update yoru bundle ID to match. Also make sure your id strings that the app requests are updated to reflect your bundle id.
Build your project in Distribution mode with the new Distribution Provisioning profile.
Upload your new binary. (Leave it un-rejected)
Set up your test in-app purchase.
Build your project in Debug mode with the new Provisioning profile.
Test request.
This is what it took to get my store working. My best guess is that the Apple back end servers get screwed up sometimes and you just need to start from scratch.
Hope this helps everyone!
iTunes Connect interface for IAP has recently been updated that can cause Invalid : < Product ID > error.
You can now add an IAP in iTunes connect without setting the price which is defaulted to USD 0 and it'll let you save that entry.
The old version of the UI would complain when you press save if you didn't edit the price field beforehand.
It is very easy to miss this field out completely and any attempt to get information using that Product ID via any iOS call would result in Invalid : < Product ID > rather than telling you it found < Product ID > priced at USD 0.