设为首页 加入收藏

TOP

获得通讯录的访问权
2017-10-13 10:29:10 】 浏览:6660
Tags:获得 通讯录 访问
 1 ABAddressBookRef abRef = ABAddressBookCreateWithOptions(NULL, NULL);
 2             if (ABAddressBookGetAuthorizationStatus() ==  kABAuthorizationStatusNotDetermined) {
 3                 ABAddressBookRequestAccessWithCompletion(abRef, ^(bool granted, CFErrorRef error) {
 4                     if (granted) {
 5                         ContactListViewController *contactListViewController = [[ContactListViewController alloc]init];
 6                         [self.navigationController pushViewController:contactListViewController animated:YES];
 7                     }
 8                 });
 9             }else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized){
10                 ContactListViewController *contactListViewController = [[ContactListViewController alloc]init];
11                 [self.navigationController pushViewController:contactListViewController animated:YES];
12             }else{
13                 UIAlertController * tipAert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请先允许访问通讯录" preferredStyle:(UIAlertControllerStyleAlert)];
14                 UIAlertAction *v1 = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
15                 }];
16                 [tipAert addAction:v1];
17                 UIAlertAction *v2 = [UIAlertAction actionWithTitle:@"前往" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
18                     [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
19                 }];
20                 
21                 [tipAert addAction:v2];
22                 [self presentViewController:tipAert animated:YES completion:nil];
23             }
24             if (abRef) {
25                 CFRelease(abRef);
26             }
27             

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇多层导航栏下的登陆注销架构 下一篇SDWebImage的使用

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目