1

I have two View Controllers. ViewController1 is the Main Screen in the app. ViewController2 is an edit/purchase Screen. I need to hide a button on ViewController1 until it has been purchased via In App Purchase on ViewController2. Any suggestions on how I would go about doing that?

I can't figure out how to get ViewController1 to know what is purchased on ViewController2

Will post code if needed.

  • What is the question? how to hide the button or how to pass information to the other viewController? Are you using Storyboard? – Gal Marom Jun 18 '14 at 16:38
  • There could be a lot of approaches to this, first of all are you using navigation controller or performing `presentmodalviewcontroller` to show `viewcontroller2` ? Are you going to show/hide button only once or you want to show button all the times after user purchases it? – SpaceDust__ Jun 18 '14 at 16:43
  • Using a navigation controller, and once purchase is made the button will always show. Thanks @spacedust –  Jun 18 '14 at 18:37

1 Answers1

0

One approach would be to use NSUserDefaults in order to save button state.

When purchase completed set a NSUserDeafult to yes

-(void)confirmPurchase
{
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"itemXPurchased"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

Since structure you are using is VC1(root)-->VC2 and you want to update VC1 which is at the bottom of viewstacks it wont automatically update itself when you pop Viewcontroller2 from stack. So you need to use either NSNotificationCenter or delegate pattern.

in your ViewController1 either for delegate or nsnotification function you can add something like

-(void)updateButton{
 if([[NSUserDefaults standardUserDefaults] boolForKey:@"itemXPurchased"])
{
  //itemXPurchased bool is set to YES you can update your button
}
}

EDIT 1: forgot to mention that user can access NSUSERDEFAULTS if they are willing to take their time and go to app's sandbox and use an app called iExplore to find the apps NSUSERDEFAULTS plist and change the values.

So if you want your app more secure use this
https://github.com/matthiasplappert/Secure-NSUserDefaults
or this
http://code.tutsplus.com/tutorials/securing-and-encrypting-data-on-ios--mobile-21263

Community
  • 1
  • 1
SpaceDust__
  • 4,844
  • 4
  • 43
  • 82