简体   繁体   中英

Checking Multiple In-App Purchase using if Statement

I am using multiple in-app purchases within my app, and I need to check, sometimes for two at once, for example, if a user has made a purchase for featureA or featureB or featureC

or perhaps they have made A & B but not C... for example;

if ([MKStoreManager featureAPurchased] && [MKStoreManager featureCPurchased] ) {

        bannerView_.hidden = YES;

What I am trying to do is say "if you have purchased feature A OR feature C then bannerView will be hidden. I know how to do it for just one (ie featureA) but if I am trying to check for if BOTH those features have been purchased, that is where I am struggling.

I guess I am doing it wrong, as it does not appear to work correctly? I am probably muddling up the statement using &&?

&& is the operator used for saying 'and'. If you want to say 'or', use || .

So, you want

if ([MKStoreManager featureAPurchased] || [MKStoreManager featureCPurchased] ) {

bannerView_.hidden = YES;

How are you checking that the user has purchased something? The usual way to check this is either have this information persisted in the app (User Defaults or database) or asking App store with -[SKPaymentQueue restoreCompletedTransactions]. Restoring transactions gives you information about all available products purchased for the user in your app, so this should give you enough to accomplish what you want

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM