设置视图安装在iPhone应用程序



我正在开发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"];
}

最新更新