2017-03-29 13 views

答えて

1

Custom login Button

// 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 
関連する問題