如何在标签栏应用程序中创建条款和条件页面

0 iphone ios

我有一个基于标签栏的应用程序,我希望创建一个条款和条件页面,仅在第一次启动应用程序时显示.

我该怎么做呢?

0x8*_*00d 6

您可以在UIAlertView中显示术语和条件作为文本或以模态方式呈现视图控制器.如果用户选择接受条款和条件并使用NSUserDefaults保存,则将Bool设置为YES.每次启动应用程序都会检查BOOL.

我使用XCode默认模板创建了一个示例项目tabbed application.这里是代码片段,显示带有条款和条件的Alert View,直到用户接受它为止.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    if(![[NSUserDefaults standardUserDefaults] valueForKey:@"acceptTermsAndConditionsBool"])
    {
        UIAlertView* tempAlert = [[UIAlertView alloc] initWithTitle:@"Terms And Conditions" message:@"Please read the terms and conditions below for using the app. We may need the app to send us app usage.. blah blah blah" delegate:self cancelButtonTitle:@"Deny" otherButtonTitles:@"Accept", nil];
        [tempAlert show];
        [tempAlert release];
    }

    // Override point for customization after application launch.
    UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
    UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) 
    {
        case 0:
        {
            exit(0);
            break;
        }
        case 1:
        {
            [[NSUserDefaults standardUserDefaults] setObject:@"YES" forKey:@"acceptTermsAndConditionsBool"];
            break;
        }

        default:
            break;
    }
}
Run Code Online (Sandbox Code Playgroud)