首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CNContact.imageData不工作

CNContact.imageData不工作
EN

Stack Overflow用户
提问于 2016-01-18 12:55:39
回答 1查看 509关注 0票数 4

我在CNContact中设置了imageData并保存,但是当我呼叫我保存的人时,headImage不起作用。

代码语言:javascript
运行
复制
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];
EN

回答 1

Stack Overflow用户

发布于 2018-01-04 19:06:33

如果您需要图像数据,则需要创建一个抓取请求。

代码语言:javascript
运行
复制
    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];
    }];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34847547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档