Store users contacts in NSMutable array after access is granted for address book

我只是一个虾纸丫 提交于 2019-12-23 04:45:53

问题


I'm using this in my viewWillAppear: to ask the user for permission/access(as apple requires) to their address book. When they have allowed access, they can proceed to an "invites" page, where they can browse through (their own)contacts that already have existing accounts on my app. Basically, I'm just going to take their contacts and put it into a UITableView. SO, I MUST GET ALL THEIR CONTACTS AND ADD IT TO AN array of type NSMutableArray. In the following code, where it says "//ADD ALL OF USERS CONTACTS TO ARRAY HERE" I need some code. What do I put there?

- (void)viewWillAppear:(BOOL)animated
{
    // Request authorization to Address Book
    ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, NULL);

    if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
        ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
            if (granted) {
                // First time access has been granted, add user's contacts to array
                // ADD  ALL OF USERS CONTACTS TO ARRAY HERE

            } else {
                // User denied access
                // Display an alert telling user that they must allow access in order to proceed to "invites" page 
            }
        });
    }
    else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
        // The user has previously given access, grab all contacts
        // ADD ALL OF USERS CONTACTS TO ARRAY HERE
    }
    else {
        // The user has previously denied access
        // Display an alert telling user that they must allow access in order to proceed to "invites" page 
    }
}

回答1:


You want ABAddressBookCopyArrayOfAllPeople().



来源:https://stackoverflow.com/questions/21081433/store-users-contacts-in-nsmutable-array-after-access-is-granted-for-address-book

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!