-4
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
    {
        // app already launched
        return NO;
    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        // This is the first launch ever
        return  YES;
    }
}

我将如何在它所在的同一个类的另一个方法中调用这个函数。

4

2 回答 2

3

这是一个委托方法,您永远不会显式调用它

应用程序完成启动后立即调用它。

于 2013-05-06T06:44:22.787 回答
1
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];

// to access the value of HasLaunchedOnce, write:
[preferences valueForKey:@"HasLaunchedOnce"]; 

// to set the value of HasLaunchedOnce, write:
[preferences setValue:TRUE forKey:@"HasLaunchedOnce"];

您可以在应用程序的任何地方使用它。

于 2013-05-06T06:48:17.153 回答