0

hi I want to do something like this. My application has a registration process. When user enter their phone number in registration page and click the registration then user get a PIN number as a SMS. Also user redirect to the PIN verification ViewController.

What I want to do is keep the user current status in the application. That means if user type the phone number and after getting the SMS without entering the PIN number to veryfi he can close the app. So next time when he open the app it should load the Verification ViewController. In order to do that I have to keep the status of the app inside my phone.

How I can store this. Can I use KeychainItemWrapper for this? If so can I make several KeychainItems by changing the identifire name.

Please help me.

Thanks

4

2 回答 2

1

您可以使用NSUserDefaults

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ...

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    NSString *registrationStatus;
    if (![defaults objectForKey@"registrationStatus"])
      registrationStatus = @"notRegistered";
    else
      registrationStatus = [defaults objectForKey@"registrationStatus"];


    if ([registrationStatus isEqualToString:@"notRegistered"]) {
        // show registration form

        // When sending the SMS, you store the current status in NSUserDefaults like this
        // [defaults setObject:@"registeredButNotValidated" forKey:@"registrationStatus"];
        // [defaults synchronize];
    } else if ([registrationStatus isEqualToString:@"registeredButNotValidated"]) {
        // show validation form

        // When validated, you store the current status in NSUserDefaults like this
        // [defaults setObject:@"registered" forKey:@"registrationStatus"];
        // [defaults synchronize];
    } else {
        // registered
    }

    return YES;
}
于 2013-10-24T08:23:07.503 回答
0

NSUserDefaults 是最简单的方法:

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:firstName forKey:@"firstName"];

并检索:

     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *firstName = [defaults objectForKey:@"firstName"];

是的,它会在应用程序关闭后保留。

于 2013-10-24T08:17:46.940 回答