0

我目前正在访问用户的联系人/通讯录。当我通过 xcode 编译程序并启动 iPhone 模拟器时,它们是数据......因为我进入了 iPhone 模拟器联系人应用程序并自己添加了它们,以查看该应用程序是否真的可以访问联系人数据库。

现在,当我通过我的 iPhone 而不是模拟器部署应用程序时,应用程序显示没有联系人,没有信息。我知道 iOS6 和苹果更改了一些隐私设置会带来一些并发症。

这是我的视图控制器类之一中的函数,我调用该函数

[self getPersonOutOfAddressBook]; 执行该功能。

- (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);
}

我的输出是

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 

在我的 IPHONE 上

在我的 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 

等等...

诡异的!!!帮助 :(

4

0 回答 0