Search code examples
iosiphonein-app-purchaseitunesin-app-billing

In-App should ask credential whenever i logout from store


I have query regarding in-app credential. I have created two sandbox account for eg accountA & accountB and one package. I have a video which require subscription to watch. If i click on video it opens the subscription page where we have 'Buy Now' button. On click on we buy a package using accountA and store this package id in NSUserDefaults.

There are two scenario now:

First:

If accountA logout from iTunes store from (Settings->iTunes store) and open the app and click on video it should ask for credential to watch video. (currently the video is playing because we are storing the package id in NSUserDefaults with irrespective of user. which i guess its wrong approach). So i want to test if the iTunes logged in user has already purchased that package should not open the subscription page. He/She should directly send to watch video.

Second:

If accountB logged in iTunes Store and open the app. He/She should not able to watch the video until unless does not buy the package for that accountB. or else he has to login with accountA to watch the video which he/she has already purchased.

So my question is how to check whether accountA or accountB has already purchase that package. I thought to make a restoreTransaction request on every time if he/she clicks on video. But if i do that then every time it opens the dialog to sign-in to iTunes store or alert comes that you have already bought this package and all which i do not want to show to user if he/she has already purchased.

I do not want to use NSUserDefault to check package has been purchase with some boolean value. I always want to check with the signed-in user.

In addition: Can we buy a package for the same installed app with two different account?


Solution

  • In your case, We have a method called "- (void)applicationWillEnterForeground:(UIApplication *)application" in appDelegate. Write your "Restoring functionality" here. So that it always check that whether the current user( Who logged into iTunes ) has purchased the subscription or not. If the user has purchased the subscription, it will call the "SKPaymentTransactionObserver" delegate method - "(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue" then set your subscription boolean variable "Yes". If user has not purchase the subscription, it calls the "- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error" delegate method, then set your subscription boolean variable "No". Based on this write delegate methods (Or) use NSNOTIFICATIONCENTER to Call the appropriate method i.e if subscritpion == yes allow user to play video else don't allow the user and show the purchasing subscription options.