无法从通讯录中获取任何联系人的图像
can't get images for any contact from contact book
下面是我的代码,但使用此代码我无法获取任何联系人的图像。
请帮助我。
- (void)loadAddressBook
{
arrContacts = [[NSMutableArray alloc]init];
APAddressBook *addressBook = [[APAddressBook alloc] init];
[addressBook loadContacts:^(NSArray <APContact *> *contacts, NSError *error)
{
if (!error)
{
for (APContact *strcontact in contacts)
{
NSMutableDictionary *addressDict=[[NSMutableDictionary alloc]init];
[addressDict setValue:strcontact.name.compositeName forKey:COMPOSITENAME];
if (strcontact.thumbnail != nil)
{
NSData *imgData = [NSData dataWithData:UIImagePNGRepresentation(strcontact.thumbnail)];
// From data to string
NSString *strImage = [[NSString alloc] initWithData:imgData encoding:NSUTF8StringEncoding];
[addressDict setObject:strImage forKey:IMAGE];
}else {
[addressDict setObject:NOIMAGE forKey:IMAGE];
}
for (APPhone *phones in strcontact.phones) {
// NSLog(@"Number %@",phones.number);
[addressDict setValue:phones.number forKey:PHONE];
}
for (APEmail *emails in strcontact.emails) {
// NSLog(@"Emails %@",emails.address);
[addressDict setValue:emails.address forKey:EMAIL];
}
for (APAddress *address in strcontact.addresses) {
// NSLog(@"Number %@",phones.number);
[addressDict setValue:address forKey:ADDRESS];
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"dd.MM.yyyy";
NSString *strDate = [formatter stringFromDate:[NSDate date]];
[addressDict setValue:strDate forKey:IMPORTDATE];
[arrContacts addObject:addressDict];
}
[tblmportContacts reloadData];
}
else
{
// show error
}
}];
}
我正在获取所有详细信息,但无法从 APAddressBook 获取图像。
请为此提供解决方案。
尝试下面的代码。
addressBook.fieldsMask = APContactFieldAll;
下面是我的代码,但使用此代码我无法获取任何联系人的图像。 请帮助我。
- (void)loadAddressBook
{
arrContacts = [[NSMutableArray alloc]init];
APAddressBook *addressBook = [[APAddressBook alloc] init];
[addressBook loadContacts:^(NSArray <APContact *> *contacts, NSError *error)
{
if (!error)
{
for (APContact *strcontact in contacts)
{
NSMutableDictionary *addressDict=[[NSMutableDictionary alloc]init];
[addressDict setValue:strcontact.name.compositeName forKey:COMPOSITENAME];
if (strcontact.thumbnail != nil)
{
NSData *imgData = [NSData dataWithData:UIImagePNGRepresentation(strcontact.thumbnail)];
// From data to string
NSString *strImage = [[NSString alloc] initWithData:imgData encoding:NSUTF8StringEncoding];
[addressDict setObject:strImage forKey:IMAGE];
}else {
[addressDict setObject:NOIMAGE forKey:IMAGE];
}
for (APPhone *phones in strcontact.phones) {
// NSLog(@"Number %@",phones.number);
[addressDict setValue:phones.number forKey:PHONE];
}
for (APEmail *emails in strcontact.emails) {
// NSLog(@"Emails %@",emails.address);
[addressDict setValue:emails.address forKey:EMAIL];
}
for (APAddress *address in strcontact.addresses) {
// NSLog(@"Number %@",phones.number);
[addressDict setValue:address forKey:ADDRESS];
}
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"dd.MM.yyyy";
NSString *strDate = [formatter stringFromDate:[NSDate date]];
[addressDict setValue:strDate forKey:IMPORTDATE];
[arrContacts addObject:addressDict];
}
[tblmportContacts reloadData];
}
else
{
// show error
}
}];
}
我正在获取所有详细信息,但无法从 APAddressBook 获取图像。 请为此提供解决方案。
尝试下面的代码。
addressBook.fieldsMask = APContactFieldAll;