在Snow Leopard上,为什么在调用[ABPerson beginLoadingImageDataForClient:]之后没有调用[<abimageclient> consumeImageData:forTag:]?</abimageclient>

时间:2012-10-13 01:29:51

标签: cocoa osx-snow-leopard abaddressbook abperson

我正在尝试在共享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的错误吗?如果是这样,是否有解决方法?

0 个答案:

没有答案