0

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:

  1. declare BOOL appPurchased; in mainMenuViewController.m after @implementation

  2. implement the following method in mainMenuViewController.m:

(void) viewWillAppear:(BOOL)animated {
    if (appPurchased) {
        [self enableLockedContent];
    } else if (!appPurchased){
        nil;
    }    
}
  1. In UnlockedContentViewController, implement the following method which is connected to a UIButton:
(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?

eggy
  • 2,836
  • 3
  • 23
  • 37
RunnerGirl
  • 53
  • 6
  • How about using the restore purchase feature for non-consumable item? http://stackoverflow.com/questions/7761556/restore-already-bought-in-app-purchases-on-iphone – Valent Richie May 27 '13 at 03:08
  • I dont want the user to have to restore the content each time they would go back to the main menu. I need to find a way for the content to remain unlocked all the time, unless the device is turned off or something like that. – RunnerGirl May 27 '13 at 03:22

1 Answers1

1

You can cast your UIViewController to be a MainMenuViewController (and then you'll be able to set the appPurchase property):

- (IBAction)toMainMenu:(id)sender {
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                             bundle:nil];
    MainMenuViewController *mainMenu = (MainMenuViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"cover"];
    mainMenu.appPurchase = YES;
    [self.navigationController pushViewController:mainMenu animated:YES];
}

You could also persist the purchase information somewhere (NSUserDefaults maybe?) and make the MainMenuViewController retrieve this information by itself (on init or even viewDidLoad methods).

Bruno Koga
  • 3,864
  • 2
  • 34
  • 45
  • thank you.I made it work with something I think similar to what you did.I declared as a BOOL property in MainMenuViewController instead of instance variable, then I could access it from other viewController in prepareForSegue method with I would have preferred to persist the data as you suggested. I think that would be the better, more professional way to do it, but don't know how to do that yet. Thanks again – RunnerGirl May 27 '13 at 13:02
  • Bruno--I worked with your code in another instance where I have a XIB file that needs to seque with MainMenuVC and send this same information (appPurchased = YES;) Since i could not use ifIdentifierIsEqualTo to egue the XIB, I went with your version instead of mine. It worked flawlessly! I will go back and change my other ViewControllers to your code since it is much more concise and cleaner. A Million thank yous for your help! – RunnerGirl May 27 '13 at 16:00