0

I am currently accessing the user's contacts/address book. When i compile the program through xcode and launch the iPhone simulator, their is data.... because I went into the iPhone simulator contacts app and added them myself to see if the app can actually access the contacts database.

Now when I deploy the app through my iPhone, not the simulator, the app shows no contacts, no info. I understand their are some complications with iOS6 and apple changing some privacy settings around.

Here's my function I have within one of my view controller classes, I call the function

[self getPersonOutOfAddressBook]; to execute the function.

- (void)getPersonOutOfAddressBook
{
    CFErrorRef error = NULL;

    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);

    if (addressBook != nil)
    {
        NSLog(@"Succesful.");

        NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
        NSLog(@"Number of users: %d ", [allContacts count]);
        NSUInteger i = 0;
        for (i = 0; i < [allContacts count]; i++)
        {
            Person *person = [[Person alloc] init];

            ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i];

            NSString *firstName = (__bridge NSString *)ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty);
            NSString *lastName =  (__bridge NSString *)ABRecordCopyValue(contactPerson, kABPersonLastNameProperty);
            NSString *fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];

            person.firstName = firstName;
            person.lastName = lastName;
            person.fullName = fullName;

            //email
            ABMultiValueRef emails = ABRecordCopyValue(contactPerson, kABPersonEmailProperty);

            NSUInteger j = 0;
            for (j = 0; j < ABMultiValueGetCount(emails); j++)
            {
                NSString *email = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(emails, j);
                if (j == 0)
                {
                    person.homeEmail = email;
                NSLog(@"person.homeEmail = %@ ", person.homeEmail);

                }

                else if (j==1)
                    person.workEmail = email;
            }

            [self.tableData addObject:person];
        }
    }

    CFRelease(addressBook);
}

My output is

2013-03-04 22:29:00.094 ourApplication[5562:907] Succesful.
2013-03-04 22:29:00.099 ourApplication[5562:907] Number of users: 0 

on my IPHONE

and on my Mac

2013-03-04 22:31:41.799 ourApplication[12591:12b03] Succesful.
2013-03-04 22:31:41.801 ourApplication[12591:12b03] Number of users: 6 

And so on...

Weird!!! HELP :(

jsetting32
  • 1,632
  • 2
  • 20
  • 45

0 Answers0