我开发了一款应用程序,它可以从iphone中获取联系人,但它在iphone 4中工作正常,但在iphone 5中也没有这样做。 视图确实加载--------
ABAddressBookRef addressBook = ABAddressBookCreate();
CFErrorRef myError = NULL;
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, &myError);
switch (ABAddressBookGetAuthorizationStatus()) {
case kABAuthorizationStatusNotDetermined: {
NSLog(@"kABAuthorizationStatusNotDetermined");
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {
// First time access.
AddressBookUpdated(addressBookRef, nil, (__bridge void *)(self));
CFRelease(addressBookRef); void insert();
}); }
break;
case kABAuthorizationStatusRestricted:{
NSLog(@"kABAuthorizationStatusRestricted");
}
break;
case kABAuthorizationStatusDenied:
NSLog(@"kABAuthorizationStatusDenied");
break;
case kABAuthorizationStatusAuthorized:{
NSLog(@"kABAuthorizationStatusAuthorized");
AddressBookUpdated(addressBookRef, nil, (__bridge void *)(self));
CFRelease(addressBookRef);
break;
}}
在此功能中获取联系人的功能我正在获取联系人&将它们带入阵列
void AddressBookUpdated(ABAddressBookRef addressBook, CFDictionaryRef info, void *context) {
@try{
NSString *userDefKey;
NSString *docsDir;
NSArray *dirPaths;
const char *dbpath;
NSString *databasePath;
sqlite3 *contactDB;
sqlite3 *db;
NSString *dbPath1;
NSString *dbPath;
NSMutableArray *data,*number,*email;
data=[[NSMutableArray alloc]init];
number=[[NSMutableArray alloc]init];
email=[[NSMutableArray alloc]init];
ABAddressBookRevert(addressBook);
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
ABAddressBookRef addressBook1 = ABAddressBookCreate();
NSArray *people1 = (__bridge NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
for ( int i = 0; i < nPeople; i++ )
{
ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );
NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
NSString *emailid;
ABMultiValueRef emailProperty = ABRecordCopyValue(person, kABPersonEmailProperty);
// ABMultiValueRef multi = ABRecordCopyValue((__bridge ABRecordRef)(person), kABPersonPhoneProperty);
//NSString *eid=(__bridge NSString *)(ABRecordCopyValue(person, kABPersonEmailProperty));
NSArray *emailArray = (__bridge NSArray *)ABMultiValueCopyArrayOfAllValues(emailProperty);
// NSInteger *i=(__bridge NSInteger*)ABRecordCopyValue(person, kABPersonPhoneMobileLabel);
if(emailArray.count==0)
[email addObject:@" "];
else{
emailid=emailArray[0];
if(emailid.length!=0)
[email addObject:emailid];
}
//NSLog(@"email array %@",eid);
if(lastName.length<1)
{
[data addObject:firstName];
}
else
{
NSString *combined = [NSString stringWithFormat: @"%@ %@",
firstName, lastName];
[data addObject:combined];
}
}
//NSLog(@"phone count is %d",data.count);
//number = [NSMutableArray arrayWithCapacity:data.count];
//NSLog(@"phone count is %d",number.count);
for(id person in people1){
//fetch multiple phone nos.
ABMultiValueRef multi = ABRecordCopyValue((__bridge ABRecordRef)(person), kABPersonPhoneProperty);
for (CFIndex j=0; j < ABMultiValueGetCount(multi); j++) {
NSString* phone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(multi, j);
//NSLog(@"phone no is %@",phone);
[number addObject:phone];
}
}
NSLog(@"data is %@",data);
NSLog(@"phone number %@",number);
NSLog(@"email id is %@",email);
}