當前我想獲取臉譜資料圖片,然後將圖片轉換成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