1

私のアプリケーションには、ウェルカム画面として読み込まれるViewControllerがあります。「実行」をタップすると、別のViewControllerが表示され、ユーザーにアカウントを作成させます。情報が送信されると、プロファイルが表示されます。(これは楽しいテストアプリです)ユーザーが登録し、プロファイルを使用してアプリを終了したときに、再登録を続ける必要がないようにしたいと思います。そのため、アプリの最初の起動を検出し、最初の起動後にWelcomeViewControllerとRegisterViewControllerを削除するためのサポートが必要です。

WelcomeViewController:

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

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"hasLaunchedOnce"]) {

    ProfileViewController *profileVC = [[ProfileViewController alloc] initWithNibName:nil bundle:nil];

    [self presentViewController:profileVC animated:NO completion:nil];

} else {

    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasLaunchedOnce"];

    [[NSUserDefaults standardUserDefaults] synchronize];

     }
}

RegisterViewController:

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

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"hasLaunchedOnce"]) {

    ProfileViewController *profileVC = [[ProfileViewController alloc] initWithNibName:nil bundle:nil];

    [self presentViewController:profileVC animated:NO completion:nil];

} else {

    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasLaunchedOnce"];

    [[NSUserDefaults standardUserDefaults] synchronize];

     }
 }
4

1 に答える 1

0

NSUserDefaults はあなたが探しているものです...ログインしたユーザーの状態を NSUserDefaults に保存し、アプリケーションの起動時にチェック/ロードします...

于 2012-07-12T13:25:04.927 に答える