【问题标题】:IOS: AddressBook Ui FrameworkIOS:地址簿 UI 框架
【发布时间】:2012-10-04 11:16:29
【问题描述】:

我想从通讯录中选择多个联系人,并且我想将所选人员的图像存储在一个可变数组中。我已经完全搜索了互联网,但我无法获得任何样品。有谁请帮忙

提前致谢

【问题讨论】:

标签: iphone objective-c cocoa-touch abaddressbook addressbookui


【解决方案1】:

首先你必须添加
“AddressBook.framework”框架并添加头文件:

导入。

// this method 
  #pragma mark- find all contacts email id
   -(void)getFilterEmailid{



NSUInteger i;
NSUInteger k;

ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *people = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);

if ( people==nil )
{
    NSLog(@"NO ADDRESS BOOK ENTRIES TO SCAN");
    CFRelease(addressBook);
    return;
}

for ( i=0; i<[people count]; i++ )
{
    ABRecordRef person = (ABRecordRef)[people objectAtIndex:i];
    NSString *home=@"";
    NSString *work=@"";
    //
    // Phone Numbers
    //
    ABMutableMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonEmailProperty);
    CFIndex phoneNumberCount = ABMultiValueGetCount( phoneNumbers );


    // Here we can get the Image ref 

    CFDataRef imageData = ABPersonCopyImageData(person);
    // This is the Image Data you can use as you want to.
    NSData *data = (NSData *)imageData;




    for ( k=0; k<phoneNumberCount; k++ )
    {
        CFStringRef phoneNumberLabel = ABMultiValueCopyLabelAtIndex( phoneNumbers, k );
        CFStringRef phoneNumberValue = ABMultiValueCopyValueAtIndex( phoneNumbers, k );
        CFStringRef phoneNumberLocalizedLabel = ABAddressBookCopyLocalizedLabel( phoneNumberLabel );    // converts "_$!<Work>!$_" to "work" and "_$!<Mobile>!$_" to "mobile"



        // Find the ones you want here
        //
        NSLog(@"-----PHONE ENTRY -> %@ : %@", phoneNumberLocalizedLabel, phoneNumberValue );
        home=[(NSString*)phoneNumberLocalizedLabel copy ];
        work=[(NSString *)phoneNumberValue copy];
        NSLog(@"home=%@  work=%@",home,work);
        CFRelease(phoneNumberLocalizedLabel);
        CFRelease(phoneNumberLabel);
        CFRelease(phoneNumberValue);

        // This is my array i save only the Email id. You can save what value you want
        [emailIdArray addObject:work];
    }


}

[people release];
CFRelease(addressBook);



}

【讨论】:

  • 用户必须从他的通讯录中选择多个联系人,我必须将这些图像存储在可变数组中
  • 好的。所以我认为为此你必须将这些数据放入表格视图中并使用表格视图作为多项选择。并将人的所有值添加到具有键值对的数组中。也许这会对你有所帮助。
  • Shameem@ 我已经阅读了联系人并将联系人数据存储在字典中,我无法在表格视图中加载这些数据。请查看此链接。我仅以这种格式获取数据. stackoverflow.com/questions/12757158/uitableview-data
猜你喜欢
  • 1970-01-01
  • 2016-05-18
  • 1970-01-01
  • 2016-07-20
  • 1970-01-01
  • 1970-01-01
  • 2014-09-01
  • 2023-03-27
  • 1970-01-01
相关资源
最近更新 更多