Byt*_*ros 0 iphone xcode facebook objective-c ios
代码非常简单,我遇到了很大的问题.我需要从Facebook URL获取图片并将其放在UIImageView上.
我不知道但不行.我也尝试了不同的链接(没有Facebook链接也不起作用).
-(IBAction)setUserPhoto:(id)sender{
NSURL *url = [url initWithString:@"http://graph.facebook.com/100000769380612/picture?type=large"];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
if(image){
NSLog(@"Image OK");
} else if (!image) {
NSLog(@"Error");
}
[userPhoto setImage:image];
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
该字符串中有一个替换变量,尚未被替换:
http://graph.facebook.com/%@/picture?type=large
Run Code Online (Sandbox Code Playgroud)
你错过了别名(这就是我把这个url放进safari时得到的错误)
使用
NSString *urlString = [NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=large", replacement]; //where replacement is the string that is supposed to go there
NSUrl *url = [NSUrl URLWithString:urlString];
Run Code Online (Sandbox Code Playgroud)
首先尝试使用Web浏览器中的URL,以确保它存在.
| 归档时间: |
|
| 查看次数: |
552 次 |
| 最近记录: |