ObjectiveFlickr - 如何在响应之前调用照片ID上的getSizes?

时间:2010-04-15 23:12:31

标签: iphone api flickr

我正在使用Flickr API和ObjectiveFlickr构建一个免费的乐器iPhone应用程序。来自兴趣列表的随机照片显示在后台,但我无法在不知道其大小的情况下居中。 (所以我可以重置UIWebView框架)

我一直在研究这个问题,如果答案非常简单,请对菜鸟有所怜悯 - 这是我第一次玩网络服务API。 =)

由于我在收到趣味性提要的回复之后才知道照片ID,我如何在响应中调用flickr.photo.getSizes?这就是我到目前为止所做的:

- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary{
 int randomResponse = arc4random() % 49;
 photoDict = [[inResponseDictionary valueForKeyPath:@"photos.photo"] objectAtIndex:randomResponse];

 NSString *photoID = [photoDict valueForKeyPath:@"id"];

 NSLog(@"%@",photoID);

 NSURL *photoURL = [flickrContext photoSourceURLFromDictionary:photoDict size:OFFlickrMediumSize];
 NSString *htmlSource = [NSString stringWithFormat:
       @"<html>"
       @"<head>"
       @"  <style>body { margin: 0; padding: 0; } </style>"
       @"</head>"
       @"<body>"
       @"<img src=\"%@\" />"
       @"</body>"
       @"</html>"
       , photoURL];

 [webView loadHTMLString:htmlSource baseURL:nil];
}

1 个答案:

答案 0 :(得分:1)

通过将返回的图像加载到UIImageView中,我实现了我想要的行为。这是代码,希望它可以帮助某人:

- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary{
    int randomResponse = arc4random() % 49;
    photoDict = [[inResponseDictionary valueForKeyPath:@"photos.photo"] objectAtIndex:randomResponse];

    NSString *photoID = [photoDict valueForKeyPath:@"id"];

    NSLog(@"%@",photoID);

    NSURL *photoURL = [flickrContext photoSourceURLFromDictionary:photoDict size:OFFlickrMediumSize];

    NSData *receivedData = [[NSData dataWithContentsOfURL:
                             photoURL] retain];
    UIImage *image = [[UIImage alloc] initWithData:receivedData] ;
    NSLog(@"%i",image.size);

    randomImage.image = image;

    //[webView loadHTMLString:htmlSource baseURL:nil];
}