0
我正在構建一個應用程序,該應用程序返回一個隨機的Facebook個人資料圖片。到目前爲止,我有下面的代碼生成一個隨機配置文件ID,有時會返回一個真實的配置文件,但有時不會,只是顯示通用的藍色臉譜。當我在實際的網站圖API上使用給定的數字時,它只是返回false。我的問題是如何將代碼放入,以便如果生成的隨機數字返回false配置文件,它會一直生成一個新的隨機數,直到返回一個真實的配置文件,從而成爲真實的圖片?在此先感謝使用Objective-C的Facebook API來查找隨機的Facebook用戶圖像
@implementation FacebookPicturesViewController
- (IBAction) nextImagePush {
NSString *prefix = @"http://graph.facebook.com/";
NSString *profileId = [NSString stringWithFormat:@"%09d", abs(arc4random())];
NSLog(@"profileId: %@", profileId);
NSString *suffix = @"/picture?type=large";
NSString* url= [NSString stringWithFormat:@"%@%@%@", prefix, profileId, suffix];
UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
[imageView setImage:img];
imageCount++;
NSLog(@"profileId: %@", profileId);
if (imageCount >= [imageArray count]){
imageCount = 0;
}
}