I am writing my first iPhone app. I am trying to add a new contact in my code, when I do so, I get the following error: Error Domain=ABAddressBookErrorDomain Code=1 "The operation couldn’t be completed. (ABAddressBookErrorDomain error 1.)".
我正在写我的第一个iPhone应用程序。我试图在我的代码中添加一个新的联系人,当我这样做时,我收到以下错误:错误域= ABAddressBookErrorDomain代码= 1“操作无法完成。(ABAddressBookErrorDomain错误1.)”。
I searched around and it seems to be something about the app may not have access to the Contacts apps, but I thought I already checked and coded to request for access if access is denied. Can someone help out pls?
我四处搜索,似乎应用程序可能无法访问联系人应用程序,但我认为我已经检查并编码,如果访问被拒绝请求访问。有人可以帮忙吗?
Here is my code:
这是我的代码:
CFErrorRef err = nil;
ABAuthorizationStatus stat = ABAddressBookGetAuthorizationStatus();
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
ABRecordRef person = ABPersonCreate();
ABMutableMultiValueRef addr = ABMultiValueCreateMutable(kABMultiStringPropertyType);
if (addressBook == nil) {
NSLog(@"error: %@", err);
}
else{
if (stat==kABAuthorizationStatusDenied || stat==kABAuthorizationStatusRestricted) {
NSLog(@"%@", @"no access. Please change privacy settings under Privacy > Settings");
}
else{
NSLog(@"Starting Contact Build...");
ABRecordSetValue(person, kABPersonFirstNameProperty, @"Jimmy", &err);
ABRecordSetValue(person, kABPersonLastNameProperty, @"Johns", &err);
ABMultiValueAddValueAndLabel(addr, @"1-123-456-7890", kABPersonPhoneIPhoneLabel, NULL);
ABMultiValueAddValueAndLabel(addr, @"jimmy@corpmail.com", kABHomeLabel, nil);
ABRecordSetValue(person, kABPersonEmailProperty, addr, nil);
ABAddressBookAddRecord(addressBook, person, &err);
ABAddressBookSave(addressBook, &err);
if (addr) CFRelease(addr);
if (person) CFRelease(person);
if (err != NULL)
{
NSLog(@"Some error... %@", err);
}
}
}
1 个解决方案
#1
0
I had same issues without access permission. i had solved with help of used below link
没有访问权限我遇到了同样的问题。我已经用下面的链接帮助解决了
The Answer was posted by Kyle here: https://*.com/a/12648938/480415
答案由凯尔在这里发布:https://*.com/a/12648938/480415
#1
0
I had same issues without access permission. i had solved with help of used below link
没有访问权限我遇到了同样的问题。我已经用下面的链接帮助解决了
The Answer was posted by Kyle here: https://*.com/a/12648938/480415
答案由凯尔在这里发布:https://*.com/a/12648938/480415