Ios 如何使用Facebook登录将应用程序引导到应用程序的主视图

Ios 如何使用Facebook登录将应用程序引导到应用程序的主视图,ios,objective-c,facebook-ios-sdk,Ios,Objective C,Facebook Ios Sdk,有人能帮助e登录屏幕吗 我已经设计了一个使用Facebook登录的移动应用程序,我已经完成了所有这些工作,但是在查看主屏幕时遇到了问题 Facebook按钮登录一个用户,然后根据我的要求将其注销,但Facebook按钮不会将用户带到主屏幕,我该怎么做 我已经拍摄了应用程序的屏幕截图,两个屏幕截图显示用户可以登录和注销,第三个屏幕截图是应用程序的主页,一旦用户登录,我希望应用程序将用户带到主页上 下面是Facebook按钮的代码 #import <FBSDKCoreKit/FBSDKCore

有人能帮助e登录屏幕吗

我已经设计了一个使用Facebook登录的移动应用程序,我已经完成了所有这些工作,但是在查看主屏幕时遇到了问题

Facebook按钮登录一个用户,然后根据我的要求将其注销,但Facebook按钮不会将用户带到主屏幕,我该怎么做

我已经拍摄了应用程序的屏幕截图,两个屏幕截图显示用户可以登录和注销,第三个屏幕截图是应用程序的主页,一旦用户登录,我希望应用程序将用户带到主页上

下面是Facebook按钮的代码

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

@interface LoginViewController ()

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
    loginButton.center = self.view.center;
    [self.view addSubview:loginButton];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}


 @end
#导入
#导入“FBSDKLoginKit/FBSDKLoginKit.h”
@接口LoginViewController()
@结束
@实现LoginViewController
-(无效)viewDidLoad{
[超级视图下载];
FBSDKLoginButton*loginButton=[[FBSDKLoginButton alloc]init];
loginButton.center=self.view.center;
[self.view addSubview:loginButton];
//加载视图后执行任何其他设置。
}
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
#pragma标记-导航
//在基于故事板的应用程序中,您通常需要在导航之前做一些准备
-(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方{
//使用[segue destinationViewController]获取新的视图控制器。
//将选定对象传递给新的视图控制器。
}
@结束


您可以使用自定义按钮并添加功能,而不是使用Facebook按钮 您可以使用以下代码

@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 {

@结束

当用户登录Facebook时,您可以使用FBSDKloginButtoneLegate捕捉事件

- (void) loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult: (FBSDKLoginManagerLoginResult *)result error:(NSError *)error { 
if (result) {
    [self perfromSegueWithIdentifier:@"YourSegueIdentifier" sender:self];
}}
我想,这可以帮助你

      NSLog(@"Logged in");
    }
  }];
}
- (void) loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult: (FBSDKLoginManagerLoginResult *)result error:(NSError *)error { 
if (result) {
    [self perfromSegueWithIdentifier:@"YourSegueIdentifier" sender:self];
}}