如何存储从Facebook图形检索图像到NSUserDefaults

时间:2015-08-18 11:48:37

标签: ios facebook-graph-api

我想从图表api链接中检索后,在NSUserDefault中存储facebook用户的图像。 这就是我发送链接的方式:

NSString *fbuid = [NSString stringWithFormat:@"%@",[result objectForKey:@"id"]];

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", fbuid]];

然后使用此URL我正在执行此操作:

NSData *data = [NSData dataWithContentsOfURL:url];
NSString *stringImage = [data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];

将其存储在用户默认值中:

[[NSUserDefaults standardUserDefaults]setObject:url forKey:@"dp"];

1 个答案:

答案 0 :(得分:0)

在这里,您可以通过多种方式使用此概念。例如

<强>一个

只需将id保存在NSUserDefaults,您需要访问

NSString *fbuid = [NSString stringWithFormat:@"%@",[result objectForKey:@"id"]];
[[NSUserDefaults standardUserDefaults]setObject: fbuid forKey:@"dp"];
[[NSUserDefaults standardUserDefaults]synchronize];

<强>提取

//此处显示图像使用方式

UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?",  [[NSUserDefaults standardUserDefaults]objectForKey:@"dp"]]]];

<强>两个    将URL字符串保存到NSUserDefaults,就像

一样
  NSString *fbuid = [NSString stringWithFormat:@"%@",[result objectForKey:@"id"]];
  NSString *URLStr=[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?", fbuid]];

[[NSUserDefaults standardUserDefaults]setObject: URLStr forKey:@"dp"];
[[NSUserDefaults standardUserDefaults]synchronize];

<强>提取

 UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?",  [[NSUserDefaults standardUserDefaults]objectForKey:@"dp"]]]];