一种快速简单的方法,用于在您的 iPhone 或 iPad 应用程序中验证 Box 用户。
将 BoxSimpleOAuth 添加到您的项目
CocoaPods
CocoaPods 是将 BoxSimpleOAuth 添加到项目的推荐方式。
- 将 BoxSimpleOAuth 添加到 Podfile:
pod 'BoxSimpleOAuth'
. - 运行
pod install
安装 pod。 - 使用
#import <BoxSimpleOAuth/BoxSimpleOAuth.h>
将 BoxSimpleOAuth 添加到您的文件中。
Carthage
- 将
github "rbaumbach/BoxSimpleOAuth"
添加到 Cartfile。 - 按照说明添加动态框架到您的目标。
从 Github 克隆
- 从 github 克隆存储库并直接复制文件,或将其作为 git 子模块添加。
- 将 'Source' 目录下的所有文件添加到您的项目。
操作方法
- 创建一个
BoxSimpleOAuthViewController
实例,并传入一个 Box 客户端 ID、客户端密钥、客户端回调 URL 和一个完成块,用于执行带有BoxLoginResponse
和NSError
参数的操作。 - 一旦
BoxSimpleOAuthViewController
实例被展示(无论是以模态或被推送到导航堆栈),它将允许用户登录。用户登录后,初始时在视图控制器中给出的完成块将被执行。完成块中的参数,BoxLoginResponse
,包含一个 accessToken 和其他由 Box API 响应 提供的登录信息。如果在尝试认证时出现问题,则将给出错误。 - 默认情况下,如果认证存在问题,将会显示一个 UIAlertView。要禁用此功能,并直接依赖 NSError,将属性
shouldShowErrorAlert
设置为 NO。 - 可以使用底层的 BoxAuthenticationManager 刷新 access_token。
- 注意:尽管视图控制器的实例可以在没有客户端ID、客户端密钥、客户端回调和完成块的情况下进行初始化(以帮助测试),但在向用户展示之前,必须使用视图控制器的属性设置这些数据。
示例用法
// Simplest Example:
BoxSimpleOAuthViewController
*viewController = [[BoxSimpleOAuthViewController alloc] initWithClientID:@"panchos_client_id"
clientSecret:@"shhhhhh, I'm a secret"
callbackURL:[NSURL URLWithString:@"http://chihuahuas.dog"]
completion:^(BoxLoginResponse *response, NSError *error) {
NSLog(@"My Access Token is: %@", response.accessToken);
}];
[self.navigationController pushViewController:viewController
animated:YES];
// Disable error UIAlertViews Example:
BoxSimpleOAuthViewController
*viewController = [[BoxSimpleOAuthViewController alloc] initWithClientID:@"pancho_jrs_client_id"
clientSecret:@"shhhhhh, I'm a secret"
callbackURL:[NSURL URLWithString:@"http://your.fancy.site"]
completion:^(BoxLoginResponse *response, NSError *error) {
NSLog(@"My OAuth Token is: %@", response.accessToken);
}];
viewController.shouldShowErrorAlert = NO;
[self.navigationController pushViewController:viewController
animated:YES];
测试
此项目已配置用于使用fastlane运行测试。
首先,在项目目录中运行setup.sh脚本来安装所需的gem和CocoaPods
$ ./setup.sh
然后,使用fastlane在命令行上运行所有的spec
$ bundle exec fastlane specs
版本历史
版本历史可以在发布页面找到。
建议、请求和反馈
感谢您考虑使用BoxSimpleOAuth进行应用内Box身份验证。任何反馈可以通过:[email protected]发送。