在iPhone应用程序中安装设置视图
答
你可以有东西出现时,应用程序是第一推出,但你不能在安装做任何事时间本身。你想在你的应用代理中这样做:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
static NSString *firstLaunchKey = @"HasLaunchedBefore";
if ([[NSUserDefaults standardUserDefaults] boolForKey:firstLaunchKey] == YES) {
// Launch your application as you normally do
} else {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:firstLaunchKey];
[[NSUserDefaults standardUserDefaults] synchronize];
// Show your first-launch views here.
}
return YES;
}
答
你可以使用NSUserDefaults API来记录应用程序已经在设备上运行的事实。
在决定显示哪些意见,使用这样的检查:
if ([[NSUserDefaults standardDefaults] boolForKey:@"hasAppLaunchedBefore"])
{
// this isn't the first time the app has run
// show normal views
}
else
{
// this is the first time the app has run
// show first-time views
[[NSUserDefaults standardDefaults] setBool:YES forKey:@"hasAppLaunchedBefore"];
}