我想从图表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"];
答案 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"]]]];