0

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 
    }
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Chisx
  • 1,976
  • 4
  • 25
  • 53
  • Why does **each and every** question about mutable arrays call that poor class an "NSMutable array"? Is "NSMutable" a sort of adjective? Or what? I hope you **do** realize that the class is called "NSMutableArray"... –  Jan 12 '14 at 23:04
  • Good call @H2CO3 Honestly I don't believe people think about it too much, just trying to be specific, but it is just an array, so you're right – Chisx Jan 12 '14 at 23:07
  • (and don't take it personal -- I've seen this *a lot* of times. Indeed, it would feel good if people paid a little more attention to details while writing their questions. But surely, there are worse things than this.) –  Jan 12 '14 at 23:11
  • Oh I don't take it personal. Honestly, I agree, and I've seen it so much I think I actually caught on to calling it an `NSMutableArray` haha. – Chisx Jan 12 '14 at 23:15

1 Answers1

1

You want ABAddressBookCopyArrayOfAllPeople().

Chuck
  • 234,037
  • 30
  • 302
  • 389