我想实现一次从通讯录中获取或加载 10 个联系人。任何可能从通讯录中检索所有联系人,但一次显示 10-10 个联系人。我正在检索所有 iphone 的图像、名字、姓氏联系人。我想实现这个以电子邮件检索电子邮件联系人,也像 10-10 个电子邮件联系人。 这是我的示例代码:
SData *imageData = (NSData *)CFBridgingRelease(ABPersonCopyImageDataWithFormat(ref, kABPersonImageFormatThumbnail)) ;
CFStringRef firstName1, lastName1;
firstName1 = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
lastName1 = ABRecordCopyValue(ref, kABPersonLastNameProperty);
NSString *name=[[NSString alloc]init];
if ([[NSString stringWithFormat:@"%@",firstName1] isEqualToString:@"(null)"] && [[NSString stringWithFormat:@"%@",lastName1] isEqualToString:@"(null)"])
{
name = @"No Name";
}
else if([[NSString stringWithFormat:@"%@",firstName1] isEqualToString:@"(null)"] && ![[NSString stringWithFormat:@"%@",lastName1] isEqualToString:@"(null)"])
{
name = [NSString stringWithFormat:@"%@",lastName1];
}
else
{
name = [NSString stringWithFormat:@"%@",firstName1];
}
name= [ name capitalizedString];
EmailandCotactsModel *emailmodel=[[EmailandCotactsModel alloc]init];
emailmodel.emailemailstring=(__bridge NSString *)(contno);
emailmodel.emailusernamestring=name;
if(!imageData)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"NoImage" ofType:@"png"];
NSData *photoData = [NSData dataWithContentsOfFile:path];
emailmodel.emailimagesData=photoData;
}
else
{
emailmodel.emailimagesData=imageData;
}
[emailarray addObject:emailmodel];
callsmsDataBool=NO;
NSLog(@"table email count %d and i %d",emailarray.count,tablecountint);
if(emailarray.count==tablecountint)
{
NSLog(@"table email reload");
tablecountint=tablecountint+10;
dispatch_async( dispatch_get_global_queue(0,0),^{
[self reloadtable];
});
NSLog(@"perform selection in bg");
}
}
}
[self.tableview reloadData];
if(!emailarray.count && [socialstring isEqualToString:@"Email"])
{
selectedlabel.text=@"Emails not found";
}
else if(emailarray.count && [socialstring isEqualToString:@"Email"])
{
// selectedlabel.text=@"Email";
selectedlabel.text=[NSString stringWithFormat:@"%ld",nPeople];
}
else if(!emailarray.count && [socialstring isEqualToString:@"SMS"])
{
selectedlabel.text=@"Phone no's not found";
}
else if(emailarray.count && [socialstring isEqualToString:@"SMS"])
{
selectedlabel.text=@"SMS";
}
else
{
selectedlabel.text=@"";
}
[tableview reloadData];
任何有价值的建议将不胜感激......
提前致谢。