Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know that SKStoreKit In App Purchses caused applicationWillResignActive?

Is it normal when you submit an In-App Purchase, that it causes applicationWillResignActive while it asks you if you want to BUY?

For example:

    [[SKPaymentQueue defaultQueue] addPayment:payment];

This causes app to resign active and then once you hit BUY or CANCEL and then applicationWillEnterForeground is called.

Is there a way to know that it was an in app purchase that caused the application to resign so that when it enters foreground again, I can flag some things to be skipped?

Thanks

like image 248
jsherk Avatar asked Jan 18 '23 09:01

jsherk


1 Answers

Ok, this is what I am going to do since I cannot think of any other way of doing it...

When an application starts up fresh it calls application:didFinishLaunchingWithOptions, and when it starts from the background it calls applicationWillEnterForeground. In both these two cases, it then always calls applicationDidBecomeActive, which is where I have the code that I want to skip when an IAP occurs.

When an application shuts down or moves to the background it always calls applicationWillResignActive and then applicationDidEnterBackground.

What I noticed is that an IAP calls applicationWillResignActive and then applicationDidBecomeActive and nothing else.

So in application:didFinishLaunchingWithOptions I will set a variable startupDidFinish=1

And in applicationWillEnterForeground I will set a variable startupForeground=1

In applicationDidBecomeActive I will do this:

    //SKIP if application resigned active then becomes active again.
    if (startupDidFinish == 1 || startupForeground==1) {
        //Do normal startup stuff

    }
    startupDidFinish = 0;
    startupForeground = 0;

So this will allow you to skip code for things like IAP (and I think also an SMS acts the same way).

like image 183
jsherk Avatar answered Jan 31 '23 02:01

jsherk