测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可证 | zlib |
发布最后发布 | 2014年12月 |
由Baris Sencan维护。
依赖于 | |
Facebook-iOS-SDK | ~> 3.17.0 |
FXKeychain | ~> 1.5.1 |
示例项目即将推出。
EasyFacebook 旨在帮助 iOS 开发者,他们在服务器上执行大多数与 Facebook 相关的工作,只需在他们的应用程序中获取用户的 Facebook 令牌即可。这个 pod 为这些开发者提供了只需要 3 个简单方法即可完成可能需要的所有事情的能力,并使他们免受通常可能在 Social Framework 和 Facebook iOS SDK 之间来回切换、处理持久性等问题所带来的任何头疼。
要求 iOS 7 或更高版本。
您可以将文件 EasyFacebook.h 和 EasyFacebook.m 复制到 EasyFacebook/Pod Classes 下的 Xcode 项目中,或者通过添加此行到 Podfile 使用CocoaPods 添加。
pod 'EasyFacebook', '~>0.1.1'
在您使用任何 EasyFacebook 方法之前,需要设置您的 Facebook App ID 以及所需的读取和发布权限。
#import <EasyFacebook.h>
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// EasyFacebook configuration.
[EasyFacebook sharedInstance].facebookAppID = @"YOUR_FACEBOOK_APP_ID";
[EasyFacebook sharedInstance].facebookReadPermissions = @[@"email"];
[EasyFacebook sharedInstance].facebookPublishPermissions = @[@"publish_actions"];
// Your Code
// ...
return YES;
}
// During the Facebook login flow, your app passes control to the Facebook iOS app or Facebook in a mobile browser.
// After authentication, your app will be called back with the session information.
// Override application:openURL:sourceApplication:annotation to call the FBsession object that handles the incoming URL
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [FBSession.activeSession handleOpenURL:url];
}
使用 EasyFacebook 编写登录方法很容易。
- (IBAction)facebookLoginButtonTapped {
[[EasyFacebook sharedInstance] openSession:^(NSString *token) {
// Facebook login succeeded and we now have a valid facebook token string.
// Send it to your servers for authentication, and then move to the next screen in the app.
} error:^(NSError *error) {
// Login failed, let the user know.
}];
}
例如,如果您的服务器将调用一个 API 端点代表用户在 Facebook 上发表内容,您可能需要确保服务器首先有一个具有发布权限的令牌。
- (void)postFacebookStatus:(NSString *)status {
[[EasyFacebook sharedInstance] requestPublishPermissions:^(NSString *token) {
// If we got to this line, then we have a valid token with both our read and publish permissions. This is guaranteed.
// Send the new token to the server, so it updates the Facebook token associated with your user.
// After the new token is sent successfully, call the end-point that you originally wanted to.
} error:^(NSError *)error {
// An error occured, handle it.
}];
}
当用户从应用程序注销时,如果有必要,应该清除 EasyFacebook 保持的任何数据,以确保 Facebook 数据不会在应用程序会话之间持续存在。
- (IBAction)logoutButtonTapped {
// Close EasyFacebook session.
[[EasyFacebook sharedInstance] closeSession];
// Clear any persistent data you stored about the currently logged in user.
}