gpt4 book ai didi

ios - 在用户登录时解析获取 facebook 个人资料图片

转载 作者:行者123 更新时间:2023-11-29 02:48:02 27 4
gpt4 key购买 nike

我是解析新手,刚刚使用解析实现了 facebook 登录。在我的应用程序中,我需要登录者的 Facebook 个人资料图片。我已经创建了该方法,但不知道是否有更简单的方法。

此方法需要时间来加载,这不是很好。当用户登录时,我可以以某种方式加载个人资料图片,然后在另一个 View Controller 中使用它吗?

这是我现在的代码:

// After logging in with Facebook
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSString *facebookId = [result objectForKey:@"id"];



image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", facebookId ]]]];


[self.tableView reloadData];
}
}];

最佳答案

这实际上与 Parse 无关。这只是 Facebook SDK。

您需要做的是将图像存储在某处,以便在图像已经存在的情况下获取它。

最简单(但可以说不是最好)的方法是使用单例。

创建一个带有属性的单例对象...

@interface MySingleton : NSObject

@property (nonatomic, strong) UIImage *userImage;

+ (instancetype)sharedInstance;

@end

然后你可以在下载前检查它是否存在...

UIImage *theImage = [[MySingleton sharedInstance] userImage];

if (!theImage) {
// download the image from Facebook and then save it into the singleton
}

一旦下载完毕,您就可以从单例中获取它,而不必每次都下载。

关于ios - 在用户登录时解析获取 facebook 个人资料图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24868282/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com