我正在尝试在我的iPhone上测试一些功能,我将拉出所有地址簿成员并将其显示在表格中。这在模拟器上工作正常,我看到像“John Appleseed”这样的模拟联系人。当我在iPhone上运行代码时,我只看到“移动用户”,显然是我。
如何查看我的所有地址簿联系人?
答案 0 :(得分: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.
}
查看此问题以获取更多信息: Programmatically Request Access to Contacts