1

我正在尝试为 shared 中的人员条目加载图像日期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雪豹上的错误吗?如果是这样,是否有解决方法?

4

0 回答 0