- (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;
}
}
我如何在它所在的同一个类的另一个方法中调用此函数。
答案 0 :(得分:3)
这是一种委托方法,你从不明确地称之为。
应用程序完成启动后立即调用。
答案 1 :(得分: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"];
您可以在应用中的任何位置使用此功能。