0

可能重复:
以编程方式请求访问 iOS 6 中的联系人

我正在尝试在我的 iPhone 上测试一些功能,其中我提取所有地址簿成员并将它们显示在表格中。这在模拟器上运行良好,我看到了像“John Appleseed”这样的模拟联系人。当我在 iPhone 上运行代码时,我只看到显然是我的“移动用户”。

如何查看我的所有通讯录联系人?

4

1 回答 1

1

在 iOS 6 中,用户必须授予应用程序使用联系信息的权限。

如果你用谷歌搜索的话,有很多这样的例子。你可以使用类似的东西:

ABAddressBookRef addressBook = ABAddressBookCreate();

__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
        accessGranted = granted;
        dispatch_semaphore_signal(sema);
    });
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
    dispatch_release(sema);   
}
else { // we're on iOS 5 or older
    accessGranted = YES;
}

if (accessGranted) {
    // Do whatever you want here.
}

查看此问题以获取更多信息: 以编程方式请求访问联系人

于 2012-11-14T16:15:12.583 回答