2013-01-23 44 views

回答

0

據我瞭解你的問題,你想從用戶的個人數據。爲此,您需要調用API AdressBook:

AdressBook API Documentation

+0

不,我試圖讓設備從配置的電子郵件帳戶值。舉例來說,如果我在我的設備中配置一個Gmail帳戶,所以我需要該郵件ID和我的項目中的其他詳細信息。 –

0

這裏工作的例子。它將所有電子郵件和全名加載到傳遞數組。以您需要的方式定製此代碼,例如,您可以找到一些特定的聯繫人並從中獲取所有信息。

- (NSMutableArray *)loadContactsFromAB:(NSMutableArray *)contacts 
{ 
     ABAddressBookRef addressBook = ABAddressBookCreate(); 
     CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); 
     CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); 

     for (int i = 0 ; i < nPeople ; i++) { 
       ABRecordRef person = CFArrayGetValueAtIndex(allPeople, i); 
       NSString *firstName = ABRecordCopyValue(person, kABPersonFirstNameProperty); 
       NSString *lastName = ABRecordCopyValue(person, kABPersonLastNameProperty); 

       NSString *fullName; 

       if (firstName && lastName) { 
         fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName]; 
       } else { 
         if (firstName) { 
           fullName = [NSString stringWithString:firstName]; 
         } else if (lastName) { 
           fullName = [NSString stringWithString:lastName]; 
         } else { 
           continue; 
         } 
       } 

       NSString *email = nil; 
       ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty); 

       if (emails) { 
         NSArray *emailAddresses = [(NSArray *)ABMultiValueCopyArrayOfAllValues(emails) autorelease]; 
         if (emailAddresses && [emailAddresses count] > 0) 
           email = [emailAddresses objectAtIndex:0]; 
         CFRelease(emails); 
       } 
       if (email) { 
         NSDictionary *contact = [NSDictionary 
               dictionaryWithObjectsAndKeys:fullName, @"name", 
               email, @"email", nil]; 
         [self addContact:contacts contact:contact]; 
       } 
       if (firstName) 
         CFRelease(firstName); 
       if (lastName) 
         CFRelease(lastName); 
     } 

     CFRelease(allPeople); 
     CFRelease(addressBook); 
     return contacts; 
} 
+0

感謝您的及時答覆,但我想獲取設備中配置的電子郵件帳戶的詳細信息。舉例來說,我在我的設備中配置了一個gmail帳戶,所以我想在Xcode中獲取郵件地址和其他詳細信息。 –

0

你不能在設置的默認電子郵件,它會只處理mfmailcomposeviewcontroller

相關問題