答案 0 :(得分:1)
// Add this to the header of your file
#import "ViewController.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
// Add this to the body
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Add a custom login button to your app
UIButton *myLoginButton=[UIButton buttonWithType:UIButtonTypeCustom];
myLoginButton.backgroundColor=[UIColor darkGrayColor];
myLoginButton.frame=CGRectMake(0,0,180,40);
myLoginButton.center = self.view.center;
[myLoginButton setTitle: @"My Login Button" forState: UIControlStateNormal];
// Handle clicks on the button
[myLoginButton
addTarget:self
action:@selector(loginButtonClicked) forControlEvents:UIControlEventTouchUpInside];
// Add the button to the view
[self.view addSubview:myLoginButton];
}
// Once the button is clicked, show the login dialog
-(void)loginButtonClicked
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile"]
fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
NSLog(@"Process error");
} else if (result.isCancelled) {
NSLog(@"Cancelled");
} else {
NSLog(@"Logged in");
}
}];
}
@end