zoukankan      html  css  js  c++  java
  • 获得通讯录的访问权

     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             
  • 相关阅读:
    PHP面向对象魔术方法基本了解
    PHP面向对象访问修饰符的基本了解
    php析构函数小结
    php构造方法(函数)基础
    php面向对象成员方法(函数)练习
    php面向对象的初认识
    用JS把数组内的日期转换为星期
    JavaScript事件(随笔)
    Spring框架的核心功能之AOP技术
    Spring框架 IOC注解
  • 原文地址:https://www.cnblogs.com/cityingma/p/5457977.html
Copyright © 2011-2022 走看看