【发布时间】:2013-04-23 13:45:17
【问题描述】:
我没有任何线索,因此我将它交给可以以适当方式帮助我的人。实际上,我已经使用 FQL 查询检索了 Facebook 朋友的详细信息,其中个人资料图片是一个该领域的,给我们带来的不便,图片是以 url 的形式检索的。早期阶段,我尝试使用图形 api(对象)获取朋友的详细信息,它访问服务器的次数与朋友的数量一样多。因为它FB 朋友需要很长时间才能同步,我前进到 FQL,这也让我很烦恼。即使我在一个查询中拥有所有朋友的图片,我无法将它们转换为图像并保存到文档文件夹很快。
我有一个 Facebook 同步按钮,在该按钮操作中,我将朋友详细信息保存/更新到数据库中,同时将朋友图片保存到文档中。这再次导致我遇到类似问题,即需要更多时间来同步。这是我理解的实现代码:
-(void)saveUpdateFriendDetails
{
for (int index = 0; index<[friendsDetailsArray count]; index++)
{
//Save or update friends details to db
//Fetch friends picture url,convert to image and save to documents folder
NSString *friendPictureString = [[self.friendsDetailsArray valueForKey:kPicture]objectAtIndex:index];
NSURL *friendPhotoUrl = [NSURL URLWithString:friendPictureString];
NSData *data = [NSData dataWithContentsOfURL:friendPhotoUrl];
UIImage *friendProfilePicture = [UIImage imageWithData:data];
NSString *filename = [facebookID stringByAppendingString:kPNG];
// Get the path of the app documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
// Append the filename and get the full image path
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:filename];
// Now convert the image to PNG and write it to the image path
NSData *imageData = UIImagePNGRepresentation(friendProfilePicture);
[imageData writeToFile:savedImagePath atomically:NO];
}
我尝试使用 GCD 和 AsyncImageView 在后台运行进程,但即便如此,它也需要相同的时间,因为进程保持不变(最终我们在后台运行,这是唯一的区别)。
那么有什么方法可以快速将朋友的图片网址转换为照片并保存到文档文件夹中,这样就不会影响我的 Facebook 同步过程。
注意:如果不将图片保存到文档中,我同步 800 个朋友大约需要 20-30 秒,保存图片也需要 2-3 分钟。
有人可以指导我吗?
提前谢谢大家:)
【问题讨论】:
标签: iphone facebook profile image friend