I have some code that runs every time the person opens the app. It works to determine whether the person logged in for the first time, or whether they are a repeat user. And based on that info, the app behaves a bit differently. But it has not been working for me as I thought it would. Here is the code:
- (void)viewDidAppear:(BOOL)animated
{
// Get user data.
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
// First arg is name and second is if not found.
NSString *user_id = [standardUserDefaults objectForKey:@"user_id"];
bool first_time_cookie = [standardUserDefaults boolForKey:@"first_time_cookie"];
[super viewDidLoad];
if(!first_time_cookie)
{
// First time on the app, so set the user cookie.
[standardUserDefaults setBool:YES forKey:@"first_time_cookie"];
[[NSUserDefaults standardUserDefaults] synchronize];
// Make new account
[standardUserDefaults synchronize];
}
else
{
// DO REPEAT USER ACTIONS
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
I am getting mixed up in my userDefaults. Would anyone be able to tell where I am going wrong? The problem that is occurring is that the system thinks that many of the repeat users are actually new users.
Thanks!