4

I have a simple issue but could not find an answer so far. I have a signup view that only appears once when the user first launches the app and once successful it is never shown again. I store this in NSUserDefaults as a BOOL. Here is how I check in the App delegate when the app is first launched:

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"returninguser"] != YES){

// First launch

}
else {
//not first launch
}

The problem I'm having is that at first launch, the [NSUserDefaults standardUserDefaults] boolForKey:@"returninguser"] is returning a YES. This is only an issue on iOS 8. It works fine on iOS 7.

Can anyone help with this please?

iosdev
  • 61
  • 5
  • Please refer this linke 'http://stackoverflow.com/questions/24840993/nsuserdefault-with-app-group-is-not-working-in-ios-8-beta3' – Ramesh Muthe Oct 12 '14 at 03:31
  • I too faced same problem, and finally I used in this way '[defaults setObject: forKey:];' – Ramesh Muthe Oct 12 '14 at 03:35
  • What version of iOS8 are you running? Some of the betas had problems with this, but it was reportedly fixed in beta 5. I tried your code in Xcode 6.0.1, on simulator 8.0 (12A365), as well as device running 8.0.2, and it works fine. – Rob Oct 12 '14 at 03:55
  • @Rob, I'm running 8.0, I'll upgrade to 8.0.2 and see if it works. I'm using Xcode 6.0.1 (6A317). Strange that it works for you on 8.0. – iosdev Oct 13 '14 at 03:32
  • @RameshMuthe, I don't see how that link would help me. – iosdev Oct 13 '14 at 03:33
  • @RameshMuthe, "'[defaults setObject: forKey:]" This is not the issue, it's reading it at first launch that returns a YES when it should be returning a NO. I'm not having a problem setting it. – iosdev Oct 13 '14 at 03:34
  • @iosdev Yeah, that link Ramesh shared with you points out that other people saw this problem you describe in the betas, but that it had appeared to have been fixed in Beta 5. I can't vouch for that, but all I know is that your code works fine for me. I don't know how else to help if I cannot reproduce the behavior you describe. Sorry. – Rob Oct 13 '14 at 03:38
  • @Rob, I appreciate your help, I'll check if it's something specific to my installation/simulator. Might try it on the real phone as well. – iosdev Oct 13 '14 at 03:48

1 Answers1

2

Ok, after playing with this some more, I found the answer to my question here: NSUserDefaults not cleared after app uninstall on simulator

As mentioned above, the problem is that the simulator seems to store NSUserDefaults even after deleting the app. That's why Rob could not reproduce the issue, it works fine the first time you try but if you delete the app and try again it doesn't work.

Community
  • 1
  • 1
iosdev
  • 61
  • 5