当前我想获取脸谱资料图片,然后将图片转换成CCSprite。获取脸谱资料图片
到目前为止我的代码如下所示:
//fbId is facebook id of someone
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=normal", fbId]];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
//convert UIImage to CCSprite
CCTexture2D *texture = [[[CCTexture2D alloc] initWithImage:image resolutionType:kCCResolutionUnknown] retain];
CCSprite *sprite = [CCSprite spriteWithTexture:texture];
[self addChild:sprite];
它的工作原理,但它采取了一会儿之前加载,大约几秒钟。
我的问题是,除了互联网连接,有没有更好的方法来尽可能快地加载Facebook个人资料图片?谢谢
谢谢,没有UI滞后了。这就是所谓的异步编程吗?在objective-c中阅读这个任何好的资源? – user1606616
是的,它被称为[GCD(Grand Central Dispatch)](https://developer.apple.com/library/mac/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html)。您可能需要检查[Paul的iOS课程](https://itunes.apple.com/itunes-u/ipad-iphone-application-development/id473757255?mt=10)作为起点。 [Block and Multithreading](https://itunes.apple.com/cn/podcast/10.-blocks-multithreading/id473757255?i=107327893&mt=2)就是这个 – onevcat
非常感谢你 – user1606616