我试图显示 twitter 图片,但当相同的东西适用于 instagram 照片 url 时,dataWithContentsOfString 返回 nil。当我使用实际 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;
});
});
}