gpt4 book ai didi

ios - 抓取特定 ABPerson 的图像时崩溃

转载 作者:行者123 更新时间:2023-12-03 12:03:44 30 4
gpt4 key购买 nike

我正在从用户的 iOS 地址簿/Contacts.app 中的联系人中抓取图像。并将它们放入字典中以 JSON 格式上传。

我收到以下错误:

2012-12-05 10:38:01.286 ContactsApp[6247:713f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSCFData)'
*** First throw call stack:
(0x2de6012 0x286ce7e 0x2de5deb 0x20926fe 0x2096b21 0x2dd3cdf 0x2dd387d 0x2dd37c5 0x20966fa 0x209262d 0x2096b21 0x2dd3cdf 0x2dd387d 0x2dd37c5 0x20966fa 0x209262d 0x20969af 0x2ddfe7c 0x2ddfa16 0x2ddf925 0x20968b8 0x2092679 0x2096b21 0x2dd3cdf 0x2dd387d 0x2dd37c5 0x20966fa 0x209262d 0x20923bd 0x209579c 0x1cad5 0x67475 0x66a87 0x14399cd 0x746008f 0x3dc253f 0x3dd4014 0x3dc52e8 0x3dc5450 0x90e36e12 0x90e1ecca)
libc++abi.dylib: terminate called throwing an exception

我使用了以下代码:

if (ABPersonHasImageData(addressBookContact)) {
NSMutableDictionary *imageDictionary = [NSMutableDictionary dictionary];
NSData *thumbnailImageData = (__bridge NSData *)ABPersonCopyImageDataWithFormat(addressBookContact, kABPersonImageFormatThumbnail);
NSData *originalImageData = (__bridge NSData *)ABPersonCopyImageDataWithFormat(addressBookContact, kABPersonImageFormatOriginalSize);
if (thumbnailImageData) [imageDictionary setObject:thumbnailImageData forKey:@"thumbnailImage"];
if (originalImageData) [imageDictionary setObject:originalImageData forKey:@"originalImage"];
[contactDictionary setObject:imageDictionary forKey:@"image"];
}

当我尝试将数组放入此请求时发生错误:

[addressBookArray addObject:contactDictionary];
if ([addressBookArray count] % 15 == 0) {
// I'm using AFNetworking
[[APIClient sharedClient] requestWithMethod:@"POST" path:@"cmd/addContact" parameters:@{ @"addressBookEntries" : addressBookArray }];
[addressBookArray removeAllObjects];
}

最佳答案

您的问题是您试图将 NSData 对象放入 JSON 对象中。不要将图像数据添加到 imageDictionary,而是将图像的 base64 编码添加到 imageDictionary,您应该没有问题。

Matt Gallagher 在此处有一个处理 base64 的便捷类:http://www.cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html

关于ios - 抓取特定 ABPerson 的图像时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13727043/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com