Avoid Interstitial to show that the app was purchased through the App Store App

Starting with iOS 11, Apple introduced the in-app purchase feature in the App Store.

Problem: Our problem is to avoid showing intermediate ads when the app wakes up due to an in-app purchase purchased from the App Store.

I am trying to control it using the new Storekit feature:

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 the application is bought in the Apple Store in one of the functions below through

Launch 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 the payment to the queue) in

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

when exactly will we see a new popup in the application?

Thanks for any answer.

+7
source share
2 answers

You are not notified of an inApp on the App Store until paymentQueue:shouldAddStorePayment:forProduct: In addition, the inApp popup does not appear if your application is not presented in paymentQueue:updatedTransactions:

This is the best I can offer you:

I assume that you do not place an interstitial ad immediately after launching your application - this will not be a very good user interface. Thus, you just need to show ads between the time when you know that the user has bought something and the processing time of this transaction.

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

  • When paymentQueue:shouldAddStorePayment:forProduct: on yourTransactionObserver is called, set doAllowIntAd = NO before returning YES to display the ad.

  • When StoreKit calls paymentQueue:updatedTransactions: on yourTransactionObserver using inApp from the App Store, you process it the same way you handle the purchase made in your application. For example, for transaction.transactionState==SKPaymentTransactionStatePurchased simply add doAllowIntAd = YES after the transaction has been processed, the content has been enabled, and [yourSKPaymentQueue finishTransaction:] to allow the interstitial to be displayed again. Of course, you must re-enable doAllowIntAd not only for SKPaymentTransactionStatePurchased , but also for some other transactionState . But you can refuse the announcement in case the transaction is delayed, for example.

Thus, if there is any delay between 3 and 4, your ad will not be displayed during this time. You can experiment to see if there is a delay in practice.

+6
source

As you already know, you should check your purchase status before showing ads.

It’s a good idea to save status somewhere in the document directory. (NSUserDefaults provides this feature for storing information in key-value pairs).

Here is a sample code, it can be useful to everyone who is trying to do this.

You can configure it to call upon a successful purchase.

 NSUserDefaults * defaults; [defaults setObject:@"Purchased" forKey:@"InAppStatus"]; 

and before deciding to show ads, you can check the status.

 if([[defaults valueForKey:@"InAppStatus"] isEqualToString:@"Purchased"]) { //App Should Unlock with No Ads } else { //Show Ads } 

Apple simply provides a way to trigger InApp purchases from your application. But you are responsible for not getting into different endless cycles.

0
source

Source: https://habr.com/ru/post/1270150/


All Articles