我正在尝试在共享ABAddressBook
中加载人员条目的图片日期。特别是,我正在打电话
-[ABPerson beginLoadingImageDataForClient:]
并将一个采用ABImageClient
并实现
-[<ABPersonClient> consumeImageData:forTag:]
我使用的方法在Mountain Lion上运行良好,但在Snow Leopard上失败了。特别是,-consumeImageData:forTag:
永远不会被调用。
以下示例命令行程序演示了我的方法:
#import <Foundation/Foundation.h>
#import <AddressBook/AddressBook.h>
@interface ImageConsumer : NSObject <ABImageClient>
@property (nonatomic, strong) NSMutableDictionary *imagesForNumbers;
@end
@implementation ImageConsumer
- (id)init
{
self = [super init];
if (self) {
self.imagesForNumbers = [NSMutableDictionary dictionary];
}
return self;
}
- (void)consumeImageData:(NSData *)data forTag:(NSInteger)tag
{
[self.imagesForNumbers setObject:data forKey:[NSNumber numberWithInteger:tag]];
NSLog(@"%s: loaded data of length %zu for tag %zd", __PRETTY_FUNCTION__, data.length, tag);
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSArray *persons = [[ABAddressBook sharedAddressBook] people];
ImageConsumer *imageConsumer = [[ImageConsumer alloc] init];
for (ABPerson *person in persons) {
NSInteger loadingKey = [person beginLoadingImageDataForClient:imageConsumer];
NSLog(@"requested data person named %@ %@ and received tag %zd", [person valueForProperty:kABFirstNameProperty], [person valueForProperty:kABLastNameProperty], loadingKey);
}
[[NSRunLoop mainRunLoop] run];
}
return 0;
}
我是否滥用ABAddressBook调用来加载ABPerson
实例的图像数据?这是雪豹ABAddressBook
的错误吗?如果是这样,是否有解决方法?