2014-05-02 25 views

回答

2
CFErrorRef error = NULL; 
    ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error); 

    __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); 
    } 
    else 
    { // we're on iOS 5 or older 
     accessGranted = YES; 
    } 


    if (accessGranted) 
    { 
     NSArray *allContacts = (__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook); 

     NSLog(@"People Count :- %d", (int)[allContacts count]); 

     for (int i = 0 ; i < [allContacts count] ; i++) 
     { 
      ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i]; 

      ABMultiValueRef emails = ABRecordCopyValue(contactPerson, kABPersonEmailProperty); 

      NSUInteger j = 0; 
      for (j = 0; j < ABMultiValueGetCount(emails); j++) 
      { 
       NSString *email = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(emails, j); 
       if (j == 0) 
        NSLog(@"Person Home Email = %@ ", email); 
       else if (j==1) 
        NSLog(@"Person Work Email = %@ ", email); 

       emailAddressList = [[EmailAddressList alloc] init]; 

       emailAddressList.strEmailAddress = email; 
       emailAddressList.strEmailAddressType = @"AddressBook"; 

       [emailAddressList InsertRecordForEmailAddress:emailAddressList]; 
      } 
     } 
    } 
+0

感谢的人....它的工作完全没有问题... – SJS

+0

这个代码显示了我emailaddresslist什么,我想要做的,有什么建议的所谓使用未声明的标识符的错误 – gowtham

相关问题