SMFBProfileImageView 0.6.0

SMFBProfileImageView 0.6.0

测试已测试
语言 Obj-CObjective C
许可证 Apache 2
发布最新发布2015年1月

Sam Miller 维护。



 
依赖
AFNetworking~> 2.3
Facebook-iOS-SDK~> 3.22
 

  • 作者:
  • Sam Miller

优点

  • 就像使用 FBProfilePictureView 类一样简单。
  • 使用 AFNetworking 库来管理图像下载,使其易于添加额外控制。
  • 修复了在 tableview 中使用 FBProfilePictureView 时的问题。见下方的 FBProfilePictureView in UITableView

FBProfilePictureView in UITableView

fbprofilepictureview_scrolling_small

这是因为将连接处理程序块调度到默认运行循环模式。因此,设置图像的连接处理程序块直到滚动完成才运行。AFNetworking 默认执行的修复措施是在调度连接处理程序时设置运行循环模式为 NSRunLoopCommonModes。您可以通过下方的 SMFBProfileImageView in UITableView 看到所做的不同。

SMFBProfileImageView in UITableView

smfbprofileimageview_scrolling_small

示例项目

要运行示例项目,首先克隆存储库,然后从 Example 目录运行 pod install

您可以直接运行应用程序,然后您将看到一个屏幕,可以输入 Facebook 用户 ID,您可以使用 Facebook 图形探索工具 找到自己的用户 ID。 如果您遇到图像加载问题,请参阅下方的 设置访问令牌

设置访问令牌

您可以为访问令牌轻松设置 Facebook 访问令牌。只需复制一个临时访问令牌(您可以直接复制 Facebook 图形探索工具 提供的令牌)。然后,在示例项目中找到 SMViewController.h 并找到以下代码部分:

/* UNCOMMENT TO USE YOUR OWN ACCESS TOKEN (you can use a temporary one
 * from http://developers.facebook.com/tools/explorer
 */
//#define kAccessToken @""

取消注释 define 行,在引号中粘贴访问令牌,让它看起来像这样

#define kAccessToken @"<your access token>"

现在,在运行示例应用程序时,将使用您添加的访问令牌查询 Facebook,您应该可以查看所有公共图像和列表示例中的所有图片。

使用方法

本类基于 Facebook-iOS-SDK 提供的 FBProfilePictureView 构建,并尝试维持与 Facebook-iOS-SDK 的相同 API,详见 Facebook iOS SDK 文档 中的描述。

基本使用

以下代码创建了一个带有用户 Facebook ID 的 SMFBProfileImageView 实例。这将自动加载用户的头像,并在加载期间显示 FB 占位符图像。

SMFBProfileImageView *profileImageView = [[SMFBProfileImageView alloc] initWithProfileID:@"<profile id>"
                                                 pictureCropping:FBProfilePictureCroppingSquare];

您也可以创建不带头像 ID 或裁剪的视图实例,并稍后设置这些属性。

// Method 1 - Use default initializer with nil ID
SMFBProfileImageView *profileImageView = [[SMFBProfileImageView alloc] initWithProfileID:nil
                                                 pictureCropping:FBProfilePictureCroppingSquare];
profileImageView.profileID = @"<facebook user ID>";

// Method 2 - Create profileImageView and set all properties later
SMFBProfileImageView *profileImageView2 = [SMFBProfileImageView new];
profileImageView2.profileID = @"<facebook user ID>";
profileImageView2.pictureCropping = FBProfilePictureCroppingOriginal;

扩展 FBProfilePictureView 的功能

默认情况下,SMFBProfileImageView 实例使用 Facebook 的 Graph API 版本 2.2,并尝试使用 Facebook SDK 的 [FBSession activeSession] 中的访问令牌。可以通过设置要使用的 API 版本或设置要使用的访问令牌来修改此行为。

SMFBProfileImageView *profileImageView = [SMFBProfileImageView new];
profileImageView.pictureCropping = FBProfilePictureCroppingOriginal;

// Set the API version to use
profileImageView.graphVersion = @"2.0";

// Set the access token to use
profileImageView.accessToken = @"<access token";

// When specifying version and/or access token to use, must set profileID afterwards
// to ensure using the new access token and version.
profileImageView.profileID = @"<facebook user ID>";

为了在一个显式设置访问令牌后,使实例使用 [FBSession activeSession] 中的访问令牌

profileImageView.accessToken = nil;

需求

为了加载每个用户头像,可能需要使用 Facebook 访问令牌。这需要按照 Facebook 入门指南 获取 App ID 并在应用中打开会话。一旦在您的应用程序中打开 FB 会话,SMFBProfileImageView 应该按预期运行。

安装

变更日志

0.5.0

  • 初次公开发布

作者

Sam Miller, [email protected]

许可

SMFBProfileImageView 允许在 Apache 2.0 许可证下使用。有关更多信息,请参阅 LICENSE 文件。