I have developed one app on iphone.
I have loaded its lite version on app store.
Now i cant to load full version from app itself, how it can be done.
I know this is possible but how this can be done.
You can do it in two ways. You have have lite and full as two separate apps, or you can have in-app upgrade. Depending on how you implement the restrictions of Lite, either one or the other might be a better choice.
In the two-app scenario, you develop Full as a separate bundle, with a separate bundle id. Xcode targets and conditional compilation might come in handy for this. In the Lite version, you want to hard-code a link to the full version in the App Store. Find out the link by copy-pasting from iTunes Connect.
In the second scenario, full/lite is a run-time setting, and the upgrade package is an in-app purchase. Implement StoreKit API, provide the hard-coded in-app product ID. Once the upgrade purchase is noticed (it's an asynchronous process), flip the setting to Full.
I'd recommend the second approach. For one thing, all reviews would go under Lite version, as opposed to splitting between Lite and Full. Also, if your app has settings or data files, those won't be lost on upgrade.
EDIT: here's how implementation of in-app purchases might look like. Somewhere in the app there's an Upgrade button (link, image, whatever) that goes like this:
if(![SKPaymentQueue canMakePayments])
{
//Display the "cannot pay here" message
return;
}
#try
{
[[SKPaymentQueue defaultQueue]
addPayment:[SKPayment paymentWithProductIdentifier: #"com.mydomain.myproduct.full"]];
}
#catch (NSException * e)
{
//Sorry...
}
Meanwhile, you need a class in your app that handles the StoreKit notifications. I mentioned that it's async; well, it still is. In my case, I used the AppDelegate for that:
#interface MyAppDelegate : NSObject <..., SKPaymentTransactionObserver>
And you designate the app delegate as one:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
//...
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
}
And then you implement the transaction processing method:
- (void)paymentQueue:(SKPaymentQueue *)q updatedTransactions:(NSArray *)tr
{
int i, n = [tr count];
for(i=0;i<n;i++)
{
SKPaymentTransaction *t = [tr objectAtIndex:i];
if(t.transactionState == SKPaymentTransactionStatePurchased)
[self ProcessPurchase: t.payment.productIdentifier];
//Support for restored transactions
if(t.transactionState == SKPaymentTransactionStateRestored)
[self ProcessPurchase: t.originalTransaction.payment.productIdentifier];
//Failed/purchased/restored
if(t.transactionState != SKPaymentTransactionStatePurchasing)
[q finishTransaction:t];
}
-(void)ProcessPurchase:(NSString*)ProgID
{
if([ProgID compare:#"com.mydomain.myproduct.full"] == 0)
{
//It's an upgrade! Change the settings, enable hidden content, and stuff...
}
}
Something like this.
You need to create separate bundle id for your full version. as these are two different application.
Related
I'm using MKStoreKit to implement an IAP into my application. Everything does as expected when purchasing the product, no error messages at all. The product is purchased using the following code..
[[MKStoreManager sharedManager] buyFeature:#"pro_upgrade"
onComplete:^(NSString* purchasedFeature)
{
NSLog(#"Purchased: %#", purchasedFeature);
// provide your product to the user here.
// if it's a subscription, allow user to use now.
// remembering this purchase is taken care of by MKStoreKit.
}
onCancelled:^
{
// User cancels the transaction, you can log this using any analytics software like Flurry.
}];
After the product has been purchased I recieve the notification (via the code below) which confirms the purchase..
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector (subscriptionPurchased:)
name: kSubscriptionsPurchasedNotification
object:nil];
After the purchase I execute the following code (as documented) to determine if the product has been purchased..
if([MKStoreManager isFeaturePurchased:#"pro_upgrade"]) {
NSLog(#"This feature is purchased.");
} else {
NSLog(#"This feature is not purchased");
}
It constantly returns NO for the product ID. This happens when running the app in the same instance as when the product was purchased as well as closing the app and opening it. Running the app using Development or Distribution certificates make no difference at all. Further more I can't find where exactly MKStoreKit stores the product purchased BOOL that it seems to be looking for (it's pretty deep in the code so i'm not saying it does or doesn't, i just can't find it). My app is storing other information using NSUserDefaults so that isn't the issue.
Any help you can offer will be extremely appreciated, thanks for your time.
MKStoreKit doesn't store in NSUserDefaults.
I use keychain instead. Place a breakpoint in the method
storeData:forKey: (writing this method name straight from my head
without looking at code, search for similarly named methods) and try
debugging it. This is the place I save your purchases.
Do remember that purchases are remembered even after deleting and
reinstalling the app.
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.
Is restoreCompletedTransactions broken in SDK 4.3 ?
I am trying to restore my auto-renewable subscription. It is not resulting in callback to updatedTransactions. Here is my code.
{
....
[appDelegate.inapp loadStore];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
....
}
Expecting callback to updatedTransactions, but do not receive it.
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
NSLog(#"IN updatedTransactions, transaction.transactionState");
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
...
...
case SKPaymentTransactionStateRestored:
NSLog(#"IN updatedTransactions, SKPaymentTransactionStateRestored");
[self restoreTransaction:transaction];
break;
}
}
}
But I do receive call to this at the end.
-(void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
}
This can still(1) happen if you're testing in the Sandbox environment and your Test User is broken. Create a new Test User in iTunes Connect, and try again.
It's not entirely clear what makes Test Users go bad; from what I gather, using them once in a non-sandbox environment can do this, but there may be other reasons as well.
(1) Xcode 4.3.1, iOS SDK 5.1
Make sure to add observer before using [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
Your code should be something like:
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
I was able to get around this but its very odd. On my testing device im getting bugged by iTunes to log in to multiple test user accounts. I usually just hit cancel and test my restore with the account that I want to restore. This time I decided to enter the password for these other annoying login boxes. It worked and next time I relaunched my app and hit restore it did not bug me to log in to the other test accounts, just the one I was testing. I proceeded with the restore and it did restore the items I wanted to see.
Id say were experinecing stupid sandbox issues and also we know apple has changed in app purchasing in general. Keep playing around with it, you'll get it to work out.
Hope this helps you out.
Products Consumable cannot be restored.
Products Non-Consumable can be restored.
Check if your products are type Non-Consumable.
You should not need the updatedTransactions callback if you are getting paymentQueueRestoreCompletedTransactionsFinished. The "queue" has a list of your transactions and you can loop thru those.
- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
for (SKPaymentTransaction *transaction in queue.transactions)
if ([myItem.productID isEqualToString:transaction.payment.productIdentifier])
myItem.purchased = YES;
}
Make sure your build number in Xcode does not have a space in it. For example "1.0 Beta". With a space updatedTransactions will not be called. Also receipt verification can fail.
Two additional points which weren't mentioned here:
If you are using Firebase make sure you add an observer before you initialize Firebase, https://firebase.google.com/docs/analytics/get-started?platform=ios
Make sure that you call finishTransaction method while handling the purchase. You won't be able to restore not completed transactions.
Our app has a list of locked products that share the same consumable product id (i.e. one consumable product id for many products). Our server provides me with a list of products and the product id associated with them:
item name="itemA" iphoneProductId="consumable.test.1"
item name="itemB" iphoneProductId="consumable.test.1"
item name="itemC" iphoneProductId="consumable.test.1"
We chose consumable because our items are created dynamically and need to be available to the user instantly (please don't reply suggesting that we use non-consumable, there are a lot of other reasons that are too hard to explain without me giving away private details about the company we are working with, as to why we are using consumable). This allows us to have multiple products share the same price.
When the user purchases itemA (for example), the item is unlocked. However, sometimes, when the user then tries to be itemB, Apple return with 'You have already purchased this but it hasn't been downloaded. Tap OK to download it now’. This should surely never happen for a consumable item. I know our system is quite complex but as far as the apple store kit is concerned, are simply just buying the same product again.
Could this just be a sandbox issue? We can't test in live as the app isn't released yet. In fact, this whole problem is holding off the release as our client is as concerned as we are about this problem.
I've followed the same code from the iphone documentation and the few in app purchase tutorials out there. I see that a lot of people on the forums seem to have witnessed the 'already purchased' dialog above for consumable products, but none of them ever get answered.
Please help! Thanks
The problem is that you are never finishing the transaction. You need to remove it from the queue.
Like:
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
I'll assume you've called -[SKPaymentQueue finishTransaction:].
Off the top of my head, there are a few possibilities:
The store hasn't received the "finish" message yet (I don't know what ordering guarantees there are).
You're trying to purchase a second item before calling finishTransaction: on the first, and the App Store thinks it's a replay.
The App Store detects when you appear to be purchasing the same item repeatedly, and assumes that something must have gone wrong.
A hack is to cycle through a list of several (10? 100?) consumables, assuming that when you get back to one earlier in the list, it will have finished processing.
An alternative solution is to pre-allocate a lot of non-consumables ("product.1", "product.2", ..., "product.100") and assign ones with the appropriate price to products on the server. Changing prices can then be done on iTunes Connect, or by assigning additional product IDs as necessary.
Thanks for your quick response, but my app does seem to be finishing the transaction, etc.
My project's in app purchase classes have become quite complex so I reverted to creating a new basic project with a test consumable product and the standard implementation of in app purchase manager/observer taken from this open source:
http://blog.mugunthkumar.com/coding/iphone-tutorial-%E2%80%93-in-app-purchases/#idc-cover
The same problem occurs. This is the order:
1. Buy the consumable product for the first time (below is the debug I printed out)
_MKStoreManager: buyFeature:test.consumable.1
__MKStoreObserver: SKPaymentTransactionStatePurchased
__MKStoreObserver: completeTransaction
_MKStoreManager: provideContent
2. "Thank you for your purchase" dialog is displayed by Apple
3. Buy the consumable product for the second time:
_MKStoreManager: buyFeature:test.consumable.1
__MKStoreObserver: SKPaymentTransactionStatePurchased
__MKStoreObserver: completeTransaction
_MKStoreManager: provideContent
__MKStoreObserver: SKPaymentTransactionStateFailed
__MKStoreObserver: failedTransaction
4. "You've already purchased this but it hasn't been downloaded. Tap OK to download it now. [Environment: Sandbox]" dialog is displayed by apple.
It just doesn't make sense in step 3 that the transaction is both purchased then failed at the same time. Do you have any ideas.
It is not worth using consumable product for non-cosumable, because Apple will reject it. Here is what happened to me:
I have had the same issue. The message explaining that you have already purchased the item appears only once in a while and mostly if you purchase a lot of things - one after the other immeadiately.
We have put it for review in the App Store anyway and got the following answer:
.....
We have completed the review of your in-app purchase but cannot post it to the App Store because the Purchasability Type is not set correctly. For information on Purchasing and Currency guidelines, please see section 11 of the App Store Review Guidelines [ https://developer.apple.com/appstore/resources/approval/guidelines.html ].
.....
The purchase of a [magazine issue] is set to "consumable", however based on product functionality it should be set as non-consumable instead.
.........
You are required to create a new in-app purchase product with the correct purchasability type.
..........
I hope this saves someone time and headaches.
I was facing the same problems. The mistake I did was deallocating the purchase before the finishTransaction was sent. Make sure you handle the transaction result after finishing the transaction
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
BOOL success = YES;
for (SKPaymentTransaction *transaction in transactions){
switch (transaction.transactionState){
case SKPaymentTransactionStatePurchased:
success = YES;
break;
case SKPaymentTransactionStateFailed:
if (transaction.error.code == SKErrorPaymentCancelled){
if(DEBUG) NSLog(#"Transaction failed => Payment cancelled.");
}else if (transaction.error.code == SKErrorPaymentInvalid){
if(DEBUG) NSLog(#"Transaction failed => Payment invalid.");
}else if (transaction.error.code == SKErrorPaymentNotAllowed){
if(DEBUG) NSLog(#"Transaction failed => Payment not allowed.");
}else if (transaction.error.code == SKErrorClientInvalid){
if(DEBUG) NSLog(#"Transaction failed => client invalid.");
}else if (transaction.error.code == SKErrorUnknown){
if(DEBUG) NSLog(#"Transaction failed => unknown error.");
}else{
if(DEBUG) NSLog(#"I have no idea.");
}
success = NO;
break;
case SKPaymentTransactionStateRestored:
success = YES;
break;
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSLog(#"transaction finished: %#", transaction);
}
if(success){
// do something
}
}
Hope that helps some of you.
Cheers,
K.
You should put this line [[SKPaymentQueue defaultQueue] finishTransaction:transaction] after the transaction over whether you are doing fresh purchase or restore purchase.
[[SKPaymentQueue defaultQueue] addTransactionObserver:observer];
make sure you have added this method on the controller handling requests.
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.