Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid Interstitial to show if the App is Purchased through App Store App

Starting from iOS 11, Apple Introduced a feature to Buy the In App purchase from App Store App.

Problem: Our problem is to avoid interstitial ad to show when the app is waking up by in-app purchase bought from the App Store App.

I am trying to manage it through the new Storekit function :

https://developer.apple.com/documentation/storekit/skpaymenttransactionobserver/2877502-paymentqueue?changes=latest_minor&language=objc

- (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)payment forProduct:(SKProduct *)product

I have two questions :

1- I would like to know if we can detect before this method is called the fact that in-app is bought from the Apple Store in one of the function below through the

launchOptions parameters ? :

- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)launchOptions

2 - When we return YES or NO (and add ourself the payment to the queue) to the

- (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)payment forProduct:(SKProduct *)product

when exactly will we see the new in-app popup ?

Thank you for any response.

like image 408
htan Avatar asked Jul 24 '17 11:07

htan


1 Answers

You are not notified of an inApp in the App Store before paymentQueue:shouldAddStorePayment:forProduct:. Also, no inApp popup occurs unless your app presents one in paymentQueue:updatedTransactions:.

This is the best thing I can suggest for you:

I'm assuming that you don't put up an interstitial ad immediately upon your app starting - that wouldn't be a very good user experience. So you just have to keep an ad from displaying between the time you know the user bought something and the time you process that transaction.

  1. So then, you can have a global variable BOOL doAllowIntAd which defaults to YES.
  2. To find out if the user bought an inApp in the App Store, very early in application:(UIApplication *)application didFinishLaunchingWithOptions:, you call [[SKPaymentQueue defaultQueue] addTransactionObserver:yourTransactionObserver]; so that your observer is set up to receive the inApp from the App Store. This is the very first thing I do in didFinishLaunchingWithOptions:.

  3. When paymentQueue:shouldAddStorePayment:forProduct: on yourTransactionObserver gets called, before returning YES, set doAllowIntAd = NO to keep the ad from displaying.

  4. When StoreKit calls paymentQueue:updatedTransactions: on yourTransactionObserver with the inApp from the App Store, you process it the same way you would process a purchase made within your app. For example, for transaction.transactionState==SKPaymentTransactionStatePurchased, simply add doAllowIntAd = YES after the transaction has been processed, content enabled, and [yourSKPaymentQueue finishTransaction:] has been called, to allow the interstitial ad to be displayed again. Of course, you should re-enable doAllowIntAd not just for SKPaymentTransactionStatePurchased, but for some other transactionState as well. But you may decide to leave the ad disabled in the case the transaction is deferred, for example.

Thus if there is any delay between 3 & 4, your ad won't display during that time. You can experiment to see whether there is any delay in practice.

like image 176
KeithL Avatar answered Oct 19 '22 14:10

KeithL