代码之家  ›  专栏  ›  技术社区  ›  Josh

如何使用Facebook SDK保存从fbprofilepictureview获取的用户图像

  •  0
  • Josh  · 技术社区  · 10 年前

    因此,我在我目前正在开发的iOS应用程序中实现了Facebook登录按钮,我试图保存用户的个人资料图片,该图片使用此行访问;

    self.profilePicture.profileID = user.id;
    

    我没有任何运气将该图像存储在应用程序的其他地方。我尝试了许多方法,包括这种方法

    imageUrl=[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?redirect=true", user.username];
    

    欢迎任何帮助!

    1 回复  |  直到 10 年前
        1
  •  1
  •   combinatorial    10 年前

    你需要使用 user.objectID 而不是 user.username .

    您也可以使用我的插件替换FBProfilePictureView, DBFBProfilePictureView 。这将imageView公开为只读属性。使用它,你的代码会是这样的。。。

    self.profilePicture.completionHandler = ^(DBFBProfilePictureView* view, NSError* error){
        if(error) {
            view.showEmptyImage = YES;
            NSLog(@"Loading profile picture failed with error: %@", error);
        } else {
            UIImage *image = view.imageView.image;
            NSData *imageData = UIImagePNGRepresentation(image);
            [imageData writeToFile:filename atomically:NO];
        }
    };