我在CNContact中设置了imageData并保存,但是当我呼叫我保存的人时,headImage不起作用。
CNMutableContact *contact = [[CNMutableContact alloc] init];
UIImage *logo = [UIImage imageNamed:@"Default"];
NSData *dataRef = UIImagePNGRepresentation(logo);
contact.imageData = dataRef;
contact.givenName = "123";
contact.phoneNumbers = phoneNums;
//添加联系人
[saveRequest addContact:contact toContainerWithIdentifier:nil];
[contactStore executeSaveRequest:saveRequest error:nil];发布于 2018-01-04 19:06:33
如果您需要图像数据,则需要创建一个抓取请求。
CNContactStore *contactStore = [[CNContactStore alloc] init];
NSPredicate *predicate = [CNContact predicateForContactsWithIdentifiers:@[[contact identifier]]];
CNContactFetchRequest *request = [[CNContactFetchRequest alloc] initWithKeysToFetch:@[[CNContactVCardSerialization descriptorForRequiredKeys],
CNContactImageDataKey,
CNContactThumbnailImageDataKey
]];
[request setPredicate:predicate];
NSError *error;
NSMutableArray *mutArray = [NSMutableArray array];
[contactStore enumerateContactsWithFetchRequest:request error:&error usingBlock:^(CNContact * _Nonnull fetchedContact, BOOL * _Nonnull stop) {
[mutArray addObject:fetchedContact];
}];
}https://stackoverflow.com/questions/34847547
复制相似问题