美文网首页
App设置UIAlertController

App设置UIAlertController

作者: 雨雪霏霏why | 来源:发表于2015-12-18 10:43 被阅读307次

App中遇到需要用户打开设置界面的需求时,可以友好的引导用户去设置界面设置,而不是只是添加个提示,让用户自己去设置(可能他们也不知道怎么设置)

这样提示用户是不是很友好呢,那如何实现呢

UIAlertController * controller = [UIAlertController alertControllerWithTitle:@"提示" message:@"123456" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction * action = [UIAlertAction actionWithTitle:@"Settiogs" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

NSURL * appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

[[UIApplication sharedApplication] openURL:appSettings];

}];

[controller addAction:action];

[self presentViewController:controller animated:YES completion:nil];

我开始在Appdelegate是这样写的(TextViewController * vc = [[TextViewController alloc]init];self.window.rootViewController = vc;(这个controller是根controller上发现界面不显示  出现这个错误Attempt to presentonwhose view is not in the window hierarchy!)当我变成这样写时

TextViewController * vc = [[TextViewController alloc]init];

UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:vc];

self.window.rootViewController = nav; 就ok了

非常重要的代码是NSURL * appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

[[UIApplication sharedApplication] openURL:appSettings];

}];

可以打开设置

相关文章

网友评论

      本文标题:App设置UIAlertController

      本文链接:https://www.haomeiwen.com/subject/knrphttx.html