ios-Facebook 登录委托方法不起作用
Posted
技术标签:
【中文标题】ios-Facebook 登录委托方法不起作用【英文标题】:ios-Facebook login delegate method isn't working 【发布时间】:2015-06-07 16:54:40 【问题描述】:目标是在用户登录后跳转到另一个ViewController,但在用户取消授权时保持原来的页面。我尝试使用委托方法但不起作用。我认为我可能不完全理解委托在 Facebook SDK 中的工作原理。我正确设置了 appDelegate,因为 Facebook 按钮工作正常。非常感谢您的帮助,因为我已经为此苦苦挣扎了很长时间! :)
// MainViewController.h
#import <UIKit/UIKit.h>
#import "AnotherViewController.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
@interface MainViewController : UIViewController <FBSDKLoginButtonDelegate>
@property (weak, nonatomic) IBOutlet id<FBSDKLoginButtonDelegate> delegate;
@property (weak, nonatomic) IBOutlet FBSDKLoginButton *FBButton;
@end
//MainViewController.m
#import "MainViewController.h"
@interface MainViewController () <FBSDKLoginButtonDelegate>
@end
@implementation MainViewController
- (void)viewDidLoad
[super viewDidLoad];
//set the delegate to self in order for the delegate protocol methods to be notified
FBSDKLoginButton *loginBtn = [[FBSDKLoginButton alloc] init];
loginBtn.delegate = self;
if ([FBSDKAccessToken currentAccessToken])
// User is logged in, do work such as go to next view controller.
UIViewController *secondCV = [[UIStoryboard storyboardWithName:@"Main" bundle:NULL]instantiateViewControllerWithIdentifier:@"AnotherViewController"];
[self presentViewController:secondCV animated:YES completion:nil];
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (void)loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error
if(!error)
NSLog(@"You've Logged in");
NSLog(@"%@", result);
//I want to go to anotherViewController after they log in
AnotherViewController *secondVC = [[AnotherViewController alloc] init];
[self presentViewController: secondVC animated:YES completion: nil];
-(void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton
【问题讨论】:
它询问电子邮件,朋友和个人资料的信息,它变得更好。它仍然返回到 MainViewController 页面......我希望它跳转到 AnotherViewController。谢谢你仍然大卫:) 【参考方案1】:我现在找到了问题所在。因为我在我的 .m 文件中声明了另一个新的 FBButton,并且我将它(在本例中为 loginBtn)设置为委托。相反,我应该设置我在 .h 文件中声明的 FBButton
self.FBButton.delegate = self;
这解决了问题。希望这能有所帮助。
【讨论】:
以上是关于ios-Facebook 登录委托方法不起作用的主要内容,如果未能解决你的问题,请参考以下文章
为啥 UICollectionView 的委托方法不起作用?