2013-08-19 31 views
0

如何在ios中從地址簿中僅獲取移動節點記錄?從地址簿中僅獲取移動節目記錄(不是來自iphone,家庭標籤等)?

我想向移動部分記錄中提取的我的陣列添加一條記錄。

我該怎麼做。我正在獲取所有電話資產記錄。但我只需要獲取移動節目記錄。

NSArray *allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(myAddressBook); 
NSLog(@"allpeople%@", allPeople); 

for (id record in allPeople) { 
    CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonPhoneProperty); 
    NSArray *phones = (NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty); 

    NSLog(@"phones %@",phones); 

    CFRelease(phoneProperty); 
    NSMutableDictionary *newRecord = [[NSMutableDictionary alloc] init]; 
    NSMutableString *newPhone = [[NSMutableString alloc] init]; 

    for (NSString *phone in phones) { 
     if(![newPhone isEqualToString:@""]) 
      [newPhone appendString:@", "]; 
     [newPhone appendString:phone]; 
    } 
+0

你想獲取從地址簿中的手機號碼? – Shivaay

+0

@popeye是啊只有手機號碼從地址簿 – user2401659

+0

那麼你爲什麼不想使用(abPerson,kabpersonphonemobilelabel)? – Shivaay

回答

0

你可以嘗試這樣的事情..

ABMultiValueRef phoneNumbers = ABRecordCopyValue(abPerson, kABPersonPhoneProperty); 
    if (phoneNumbers) { 
     CFIndex numberOfPhoneNumbers = ABMultiValueGetCount(phoneNumbers); 
     for (CFIndex i = 0; i < numberOfPhoneNumbers; i++) { 
      NSString *phone = (__bridge_transfer NSString *)ABMultiValueCopyValueAtIndex(phoneNumbers, i); 
      CFStringRef label = ABMultiValueCopyLabelAtIndex(phoneNumbers, i); 
      if (label) { 
       if (CFEqual(label, kABPersonPhoneMobileLabel)) { 
        primaryPhoneText.text = phone; 
       } else { 
       } 
       CFRelease(label); 
       [allPhones addObject:phone]; // allPhones is an array here. 
      } 
     } 
     CFRelease(phoneNumbers); 
    } 

希望這將幫助你..

享受編碼..

+0

這是我的工作代碼.. – Shivaay

相關問題