I have built an app that includes an IAP
(In App Purchase
). The app is built using a UINavigationController
. When the user decides to purchase the content, the unlock feature unlocks the content. The user then taps on the back button, and they are taken back to the main menu, where they can then access the rest of the app. All of this works fine.
My problem is that when the user goes to an unlocked viewController
that is part of the UINavigationController
, then returns to the main menu page, the app has cleared its memory of the fact that the user has purchased the unlocked content and (I am assuming) uses the property.enabled = no;
attribute that is set in the viewDidLoad
method of this initial main menu viewController
to re-lock content when the main page is reloaded.
So, my question is how can I let the app know that the user has purchased the in-app content, and to keep the content unlocked after the user has strayed from the main menu page?
I am thinking that maybe I can declare BOOL appPurchased;
in the mainMenuViewController
. Then from the newly unlocked viewControllers
, include a prepareForSegueMethod
that sets the BOOL
to YES
which will in turn enable the purchased content in an if
statement.
Something like this:
declare
BOOL appPurchased;
inmainMenuViewController.m
after@implementation
implement the following method in
mainMenuViewController.m
:
(void) viewWillAppear:(BOOL)animated { if (appPurchased) { [self enableLockedContent]; } else if (!appPurchased){ nil; } }
- In
UnlockedContentViewController
, implement the following method which is connected to aUIButton
:
(IBAction)toMainMenu:(id)sender { UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *mainMenu = [mainStoryboard instantiateViewControllerWithIdentifier:@"cover"]; [self.navigationController pushViewController:mainMenu animated:YES]; }
I can't figure out how to write MainMenuViewController.appPurchase =YES;
in the above (IBAction)toMainMenu:(id)sender
method.
Is this configuration of sending a BOOL
value back to the mainViewController
anywhere close to working? Is there a better way?