在我的应用程序中,我正在获取联系信息直接购买这样做......
ABAddressBookRef m_addressbook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);
for (int i=0;i < nPeople;i++)
{
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
CFStringRef company,firstName,lastName;
firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
lastName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
company = ABRecordCopyValue(ref, kABPersonOrganizationProperty);
}
所以,我需要先检查这是否是我的应用程序的 ON/OFF 设置 --> 隐私 --> 联系人 ON/OFF。
为此,我正在这样做:
__block BOOL accessGranted = NO;
float sysver = [[[UIDevice currentDevice]systemVersion]floatValue];
if(sysver>=6) {
ABAddressBookRef addressBook = ABAddressBookCreate();
if (ABAddressBookRequestAccessWithCompletion != NULL) {
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 {
accessGranted = YES;
}
} else {
accessGranted = YES;
}
if(accessGranted)
{
// doing my stuff and moving on
} else {
// please make Settings --> Privacy --> Contacts my app. ON for accessing contacts.
}
我的问题是,在设备上安装应用程序后的第一次,应用程序要求我“不允许”/“确定”提醒联系人授予访问权限。我点击了确定,但设置->隐私->我的应用程序的联系人已关闭,因此再次收到警报以使其打开,“设置”“确定”因此选择了设置,我将其打开,一旦我将其打开app get SIGKILL nothing to console。
后来每当我将隐私设置更改为关闭时,应用程序在后台崩溃。我得到 SIGKILL 没有什么可以安慰的。
提前致谢。