Question

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 
    }
}
Was it helpful?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top