2015-07-20 97 views
0

我是新来的iOS和Objective-C,我想通过Facebook执行登录,所以我设法把FBSDKLoginButton,但我无法通过委托获得结果。我遵循官方指南,但仍然不适合我。 这是.h文件ios facebook登录按钮结果

// 

#import <UIKit/UIKit.h> 
#import <FBSDKCoreKit/FBSDKCoreKit.h> 
#import <FBSDKLoginKit/FBSDKLoginKit.h> 

@interface LoginViewController : UIViewController <FBSDKLoginButtonDelegate> 

@property (weak,nonatomic) IBOutlet FBSDKLoginButton *loginButton; 



@end 

,这是.m文件

// 


#import "LoginViewController.h" 
#import "CreatePartyViewController.h" 


@interface LoginViewController() 

@end 

@implementation LoginViewController 

@synthesize loginButton; 




-(void)alredyLogged{ 

//[self performSegueWithIdentifier:@"loginS" sender:self]; 
} 

-(void)viewDidAppear:(BOOL)animated{ 
if([FBSDKAccessToken currentAccessToken]){ 
    [self alredyLogged]; 
    NSLog(@"alredy_logged"); 
} 
} 

- (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton{ 
NSLog(@"logout"); 
} 

- (void)loginButton:(FBSDKLoginButton *)loginButton 
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result 
      error:(NSError *)error { 
NSLog(@"Login"); 
} 


- (void)viewDidLoad { 
[super viewDidLoad]; 
loginButton.delegate = self; 






loginButton.readPermissions = @[@"public_profile", @"user_friends"]; 
loginButton = [[FBSDKLoginButton alloc]init]; 




[FBSDKProfile enableUpdatesOnAccessTokenChange:YES]; 

// Do any additional setup after loading the view. 
} 


@end 
+0

使用这种方法.. HTTP: //stackoverflow.com/questions/31528948/make-button-touchupinside-fbloginview/31562976#31562976 点击此链接。 – Ananth

+0

对代码进行快速扫描,似乎是在初始化它之前设置属性。在一个不相关的笔记上,很高兴看到你如何将它添加到视图中。我建议查看https://developers.facebook.com/docs/facebook-login/ios#login-button,以防你没有 – corvuszero

回答

1

它可能是你没有设置的Facebook按钮的代表? 你可以做到这一点无论是在故事板,通过按钮的委托连接到它坐在视图 - 控制,或通过声明

loginButton.delegate=self; 

- (无效)viewDidLoad方法。

0

把代表FBSDKLoginButtonDelegate在你的头文件,

@interface YourViewController : UIViewController <FBSDKLoginButtonDelegate> 

而在你的* .m文件添加这个方法:

- (void) loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error{ NSLog(@"LOGGED IN TO FACEBOOK"); // whatever method you want here }