我试图显示推特图片但是dataWithContentsOfString返回零,当相同的确切的东西适用于Instagram照片网址时。当我使用实际的url而不是从nsdictionary
获取它时,它可以工作NSString *twitterString = @"http://pbs.twimg.com/media/BYWHiq1IYAAwSCR.jpg"
但不喜欢这个
if ([post valueForKeyPath:@"entities.media.media_url"]) {
NSString *twitterString = [NSString stringWithFormat:@"%@", [post valueForKeyPath:@"entities.media.media_url"]];
NSURL *twitterPhotoUrl = [NSURL URLWithString:twitterString];
dispatch_queue_t queue = kBgQueue;
dispatch_async(queue, ^{
NSData* data = [NSData dataWithContentsOfURL:twitterPhotoUrl];
UIImage *image = [UIImage imageWithData:data];
dispatch_sync(dispatch_get_main_queue(), ^{
[streamPhotoArray replaceObjectAtIndex:indexPath.row withObject:image];
cell.twitterPhoto.image = image;
});
});
}