CNContact.imageData不起作用

时间:2016-01-18 04:55:39

标签: cncontact

我在CNContact中设置了imageData并保存,但当我打电话给我保存的人时,headImage无法正常工作。

keyPressed(noteData) {
    console.log(noteData); // {key: 30, keyType: "white"}
    this.pressed = noteData;
    noteCanvas.drawImage();
}

1 个答案:

答案 0 :(得分:0)

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

    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];
    }];
}