2016-03-24 17 views
0

任何人都可以通過登錄屏幕來幫助您?如何使用Facebook登錄將應用程序指向應用程序的主視圖

我設計了一個使用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 

enter image description here

enter image description here

回答

0

而不是使用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 { 
 // here you can push or present controller 
 NSLog(@"Logged in"); 
    } 
    }]; 
} 

@end

0

可以使用FBSDKLoginButtonDelegate因爲當用戶在Facebook正在追趕loged事件。

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

我想,這可以幫助你。

相關問題