简体   繁体   中英

Displaying terms and conditions on AppDelegate

I want to display a UIAlertController for terms an conditions on appdelegate first, if the user click "Agree", I can then procced to my viewController but if the user click "Cancel", then the app should remain on Splash screen. I have the below code but it shows my viewController without uinavigationController and with no functionality.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    userDefaults = [NSUserDefaults standardUserDefaults];
    if (![userDefaults boolForKey:@"TermsAndConditions"]) {

        _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
        _window.rootViewController = [[UIViewController alloc] init];
        _window.windowLevel = UIWindowLevelAlert;
        _window.backgroundColor = [UIColor prosenseWhiteColor];

        UIImageView *windowImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Defaulte"]];
        [windowImage setFrame:[UIScreen mainScreen].bounds];
        [windowImage setContentMode:UIViewContentModeScaleAspectFit];
        [_window addSubview:windowImage];

        [_window makeKeyAndVisible];

        NSString *path = [[NSBundle mainBundle] pathForResource:@"termsAndConditions" ofType:@"txt"];
        NSString *tsAndCs = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];

        UIAlertController *termsAndConditionsController = [UIAlertController alertControllerWithTitle:@"Terms and conditions" message:tsAndCs preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *agree = [UIAlertAction actionWithTitle:@"Agree" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){

            [self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];

            [userDefaults setBool:YES forKey:@"TermsAndConditions"];
            [userDefaults synchronize];

                        UIStoryboard *st_board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
                        PTPdfFileListViewController *pdfFileListView = (PTPdfFileListViewController*)[st_board instantiateViewControllerWithIdentifier:@"PTPdfFileListViewController"];
                        self.window.windowLevel = UIWindowLevelNormal;
                        [self.window makeKeyAndVisible];
                        [(UINavigationController*)self.window.rootViewController presentViewController:pdfFileListView animated:NO completion:nil];
        }];

        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
            NSLog(@"Cancel");
        }];

        [termsAndConditionsController addAction:cancel];
        [termsAndConditionsController addAction:agree];
        [_window.rootViewController presentViewController:termsAndConditionsController animated:YES completion:nil];

    }else {
        NSLog(@"accepted terms already");
    }
}

what is it that Im doing wrong ?

您应该以根用户身份将PTPdfFileListViewController嵌入UINavigationController中,并提供该UINavigationController。

Try using pushViewController instead of presentViewController , then it will be in your main application's navigation controller.

The user will be able to go back, so I'm not sure it's the solution you're looking for.

Solution without the back button:

[(UINavigationController*)self.window.rootViewController setViewControllers:@[pdfFileListView] animated:NO];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM