0

i have used following code for getting for getting information from address book

ABRecordRef ref = CFArrayGetValueAtIndex(allPeopleName, i );
        NSString* personName = (__bridge_transfer NSString*) ABRecordCopyValue(ref, kABPersonFirstNameProperty);
        NSDate* Date = (__bridge_transfer NSDate*) ABRecordCopyValue(ref, kABPersonBirthdayProperty);
         **NSString* personEmail = (__bridge_transfer NSString*) ABRecordCopyValue(ref, kABPersonEmailProperty);**
          NSString *birthdayDate = [dateFormat stringFromDate:Date]; 
        **NSLog(@"personEmail%@",personEmail);**

// this is what personaEmail prints

personEmailABMultiValueRef 0x8a64740 with 2 value(s) 0: $!!$ (0x8a2bea0) - miou@yahoo.in (0x8a41df0) 1: $!!$ (0x8a423c0) - minadi@yahoo.com (0x8a64720)

        ABMultiValueRef phones = (ABMultiValueRef)ABRecordCopyValue(ref, kABPersonPhoneProperty);
        NSString* mobile=@"";
        NSString* mobileLabel;
        for (int i=0; i < ABMultiValueGetCount(phones); i++) {
            //NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(phones, i);
            //NSLog(@"%@", phone);
            mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
            if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel]) {
                NSLog(@"mobile:");
            } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel]) {
                NSLog(@"iphone:");
            } else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhonePagerLabel]) {
                NSLog(@"pager:");
            }
            [mobile release];
            mobile = (NSString*)ABMultiValueCopyValueAtIndex(phones, i);
            NSLog(@"%@", mobile);
            NSCharacterSet* charactersToRemove = [[NSCharacterSet decimalDigitCharacterSet] invertedSet] ;
            mobile = [[mobile componentsSeparatedByCharactersInSet:charactersToRemove] componentsJoinedByString:@""] ;


    }   

now my question are

  how can i get only email from that all other stuff
  i always want only one email id not two how can i get only home email id? doesnt matter how many email ids are there in address book
4

2 回答 2

0
   This will print all the email id. You can take the necessary one.

  NSString *email;
  CFStringRef value, label;
   ABMutableMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty);
    CFIndex count = ABMultiValueGetCount(multi);
  if (count == 1)
  {
    value = ABMultiValueCopyValueAtIndex(multi, 0);
    email = (__bridge NSString*) value;
    NSLog(@"EmailID   %@",email);
    CFRelease(value);
}
else
{
    for (CFIndex i = 0; i < count; i++)
    {
        label = ABMultiValueCopyLabelAtIndex(multi, i);
        value = ABMultiValueCopyValueAtIndex(multi, i);

        // check for Work e-mail label
        if (CFStringCompare(label, kABWorkLabel, 0) == 0)
        {
            email = (__bridge NSString*) value;
            NSLog(@"EmailID   %@",email);
        }

        // check for Home e-mail label
        else if(CFStringCompare(label, kABHomeLabel, 0) == 0)
        {
            email = (__bridge NSString*) value;
            NSLog(@"EmailID   %@",email);
        }

        CFRelease(label);
        CFRelease(value);
      }
  }
   CFRelease(multi);
于 2013-04-02T06:41:54.233 回答
0

personEmail(或者,更准确地说,ABRecordCopyValue(ref, kABPersonEmailProperty))的返回值不是NSString. 查看日志消息 - 它是一个ABMultiValueRef.

您将需要使用本文档中描述的方法来访问各个组件。

于 2013-04-02T06:25:35.730 回答