zoukankan      html  css  js  c++  java
  • 用xcode 5 开发访问IOS 7上面的通讯录有问题

    NSMutableArray *addressBookTemp = [NSMutableArray array];
    
    ABAddressBookRef addressBooks = ABAddressBookCreate();
    
    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBooks);
    
    CFIndex nPeople = ABAddressBookGetPersonCount(addressBooks);

    这段代码在IOS6是可以读取通讯录的,但在IOS7下面就不行,程序没报错,调试时候发现返回的都是nil,有木有朋友遇到这个问题?

    找到原因了,原来IOS7需要隐私验证,调用通讯录里面API需要以下代码作为权限认证:

        __block BOOL accessGranted = NO;
        if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined)
        { ABAddressBookRequestAccessWithCompletion(addressBooks, ^(bool granted, CFErrorRef error)
            {
                // First time access has been granted, add the contact accessGranted = granted;
            });
        }
        else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized)
        {
            // The user has previously given access, add the contact accessGranted = YES;
        }
        else
        {
            // The user has previously denied access // Send an alert telling user to change privacy setting in settings app
        }
  • 相关阅读:
    How Many Answers Are Wrong(带权并查集)
    Dice
    Plants vs. Zombies(二分好题+思维)
    Marriage Match IV(最短路+网络流)
    Treasure Hunt
    The Doors(几何+最短路,好题)
    90. Subsets II
    89. Gray Code
    88. Merge Sorted Array
    87. Scramble String
  • 原文地址:https://www.cnblogs.com/ygm900/p/3472077.html
Copyright © 2011-2022 走看看