• 用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
        }
  • 相关阅读:
    [HNOI2012]永无乡
    [HNOI2011]括号修复 / [JSOI2011]括号序列
    [NOI2005]维护数列
    文艺平衡树(Splay)
    SP2713 GSS4
    SP1716 GSS3
    Cookie和Session
    Session和Cookie的区别与联系
    Django ORM 多对多操作 使用聚合函数和分组 F查询与Q查询
    csrf攻击
  • 原文地址:https://www.cnblogs.com/ygm900/p/3472077.html
Copyright © 2020-2023  润新知