Ios 在AppDelegate上显示条款和条件
我想显示一个Ios 在AppDelegate上显示条款和条件,ios,objective-c,Ios,Objective C,我想显示一个UIAlertController以了解appdelegate上的条款和条件,首先,如果用户单击“同意”,我可以进入我的viewController,但如果用户单击“取消”,则应用应保持在初始屏幕上。我有下面的代码,但它显示了我的viewController,没有uinavigationController,也没有任何功能 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(N
UIAlertController
以了解appdelegate
上的条款和条件,首先,如果用户单击“同意”,我可以进入我的viewController,但如果用户单击“取消”,则应用应保持在初始屏幕上。我有下面的代码,但它显示了我的viewController,没有uinavigationController,也没有任何功能
- (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");
}
}
我做错了什么?你应该在UINavigationController中嵌入PTPdfFileListViewController作为根目录,并将该UINavigationController呈现出来。尝试使用
pushViewController
而不是presentViewController
,然后它将出现在主应用程序的导航控制器中
用户将能够返回,因此我不确定这是您正在寻找的解决方案
不带后退按钮的解决方案:
[(UINavigationController*)self.window.rootViewController setViewControllers:@[pdfFileListView] animated:NO];
希望您将“viewController”设置为初始viewController。这可能是溅泼屏幕后显示空白视图控制器的原因。你能查一下吗?谢谢。你为什么把这件事弄得太复杂了。只要创建一个UIveiw,并在rootviewcontroller上显示它一次,然后就不加载它了。@Nitin Gohel我已经尝试过了,我认为可能有更好的方法,因为您建议的方法是先显示rootview 2秒钟,然后显示uiview的条款和条件