Facebook login is redirecting to logout page - ios

I have set up a Facebook login for my app and it works but what I don't know how to do is when you log in the app through Facebook, the app should take you to a menu screen that I have created in a view controller. Right now with Facebook login it is taking me to the log out page. Any help would be appreciated.
In my ViewController:-
- (void)viewDidLoad{
[super viewDidLoad];
FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
loginButton.readPermissions = # [#"public_profile", #"email", #"user_friends"];
[self.view addSubview:loginButton];
if ([FBSDKAccessToken currentAccessToken]) {
[self performSegueWithIdentifier:#"Cell" sender:self];
}
}
I am checking if the user is logged in, and if yes perform the segue nothing happens.

When your facebook request complete the authentication process, the FB button is automatically turned into "log-out" mode since that is the next option for the user. To transition to a new view controller you can call a segue in the delegate method as shown below. This method will be called at the end of the FB credentialing, if you have subscribed to the delegate FBSDKLoginButtonDelegate:
- (void)loginButton:(FBSDKLoginButton*)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult*)result
[self performSegueWithIdentifier:#"yourSegueIdentifier" sender:self];
}

Related

Safariviewcontroller reloads content when open another app then return

I am trying to implement an SSO scenario with using sfsafariviewcontroller. The scenario is below.
The user opens the app, and the login page displays in wkwebview.
User clicks login button then safariviewcontroller opens the SSO page.
The user enters username and password then presses login button in SSO page.
For two-step verification, the user enters an SMS-pin in next SSO page and presses the Done button.
When verification completes, the user automatically returns with authorized state.
The problem is at step 4. When the user opens messages to get the SMS-pin and returns to the app, the sfsafariviewcontroller reloads the page with the initial URL. So the user cannot enter the SMS-pin.
Why does SfSafariViewController reload the page with the initial URL every time?
The implementation is below.
#interface WebContentViewController()<SFSafariViewControllerDelegate>
...
#end
#implementation WebContentViewController
...
...
- (BOOL)decideNavigationFlow:(NSURL *) url isLinkClicked: (BOOL) isLinkClicked {
....
....
if(IS_IOS9_OR_GREATER){
SFSafariViewController *svc = [[SFSafariViewController alloc] initWithURL:url];
[self presentViewController:svc animated:YES completion:nil];
}
}
-(void)safariViewController:(SFSafariViewController *)controller didCompleteInitialLoad:(BOOL)didLoadSuccessfully {
LogInfo(#"#######Initial load completed");
}
-(void)safariViewControllerDidFinish:(SFSafariViewController *)controller {
LogInfo(#"#######Done pressed");
}
#end

how to direct the application using Facebook login to the main view of the application

can anybody help e with the login screen?
i have designed a mobile application that uses Facebook login, I've got all of that working but having issue to view the main screen.
The Facebook button logs in a user and logs them out which i wanted, but the Facebook button does not take the user to the main screen how do i do that?
i have taken screen shot of the application, the two screen shot show a user can log in and log out and the third screen shot is the home page of an application, once the user have logged in, i want the application to take the user onto the main page.
the following is the code for Facebook button
#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
Instead of using Facebook button you can use custom button and add functionality
you can use following code
#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
You can use FBSDKLoginButtonDelegate for catching event when user is loged in Facebook.
- (void) loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult: (FBSDKLoginManagerLoginResult *)result error:(NSError *)error {
if (result) {
[self perfromSegueWithIdentifier:#"YourSegueIdentifier" sender:self];
}}
I think, this can help you.

Facebook API permissions in iOS

I'm working on an app that uses the Facebook SDK. Until now I've not had any significant problems. I've been using the API to request a user's photos. However, after deleting the app on the device to try out some log-in scenarios, the app now only requests the public profile.
This is the call being made
self.loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"public_profile", #"email", #"user_friends", #"user_photos"]];
but this is what shows on the device
When I request the user's photos the data is empty (as you'd expect with just the public profile).
What did I do to break it? And more importantly, how do I fix it?
EDIT: I've created a new app on the Facebook developer portal and I get exactly the same results.
For reasons I can't establish, this error was somehow connected to the way that the FBLogin was initialising.
In my app I had created an FBLoginView in the storyboard and I was doing the alloc/init in the viewDidLoad method of the view controller handling my Facebook information.
I had checked to ensure that the FBLoginView class was associated with the view in the storyboard and that the FBLoginView class was declared in my app delegate.
However, I was seeing the problem as stated. It was only when I removed the FBLoginView from the storyboard and created it programmatically (as in the FBLoginUIControlSample that's available on Facebook) that the problem was resolved.
For reference, this DID NOT work for me
-(void)viewDidLoad{
[super viewDidLoad];
self.loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"public_profile", #"email", #"user_friends", #"user_photos"]];
self.loginView.delegate = self;
}
This DID work.
-(void)viewDidLoad{
[super viewDidLoad];
FBLoginView *loginView = [[FBLoginView alloc] initWithReadPermissions:#[#"public_profile", #"email", #"user_friends", #"user_photos"]];
loginView.delegate = self;
loginView.frame = CGRectOffset(loginView.frame,
(self.view.center.x - (loginView.frame.size.width / 2)),
5);
loginView.center = self.view.center;
[self.View addSubview:loginView];
}

Implementing conditional segue with custom delegate

I am using storyboard. It has a login VC , which on success pushes to another VC. When the user enters the credentials and clicked on login button then it hits the server. I have implemented all the logic that contains hitting with server in a separate class which has delegate. When we get response then the control goes to the delegate method implemented in login VC. In the delegate method if status is success then only the login VC must be pushed in to another VC.
In Login VC
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
Util *util = [[Util alloc]init];
util.delegate = self;
NSMutableDictionary *request = [[NSMutableDictionary alloc]init];
[request setValue:uname.text forKey:#“username”];
[request setValue:pwd.text forKey:#“password”];
[util body:request];
}
when server returns response it comes to the delegate method implemented in Login VC
- (void)response:(NSDictionary *)response
{
//here i am going to check the status if it is success i will go to new VC else in same VC
}
here i am unable to go to another VC since i am not in the shouldPerformSegueWithIdentifier: method.
Why don't you call
[self performSegueWithIdentifier:#"customerView" sender:self];
It looks like you're probably triggering your segue when the login button is tapped. You can't do this if you need to wait for a response from your web service. Instead, try connecting your button to a method when sends off your login request. When you receive your response, you can check if the user's login is valid, and then perform your segue programmatically:
- (void)response:(NSDictionary *)response
{
if (something) // check if response is valid
{
[self performSegueWithIdentifier:#"YourSegueIdentifier" sender:self];
}
else
{
// show error
}
}
This way, you won't need to implement shouldPerformSegueWithIdentifier:sender: at all.

Implement sign in via twitter in ios

I want to provide functionality to get user sign in via twitter in my app.
I have spend 2 days in just reading the blogs , dev.twitter.com .. but i reached nowhere.
Can anyone help me .. or just tell me any open source app. thats provides this functionality..
thanks
If you develop for IOS 5 and later versions just add Twitter.framework to your target.
User uses settings screen to login and logout to twitter
#import <Twitter/Twitter.h> in your class/viewcontroller.
then call following method anywhere in your code
if ([TWTweetComposeViewController canSendTweet])
{
//yes user is logged in
}
else{
//show tweeet login prompt to user to login
TWTweetComposeViewController *viewController = [[TWTweetComposeViewController alloc] init];
//hide the tweet screen
viewController.view.hidden = YES;
//fire tweetComposeView to show "No Twitter Accounts" alert view on iOS5.1
viewController.completionHandler = ^(TWTweetComposeViewControllerResult result) {
if (result == TWTweetComposeViewControllerResultCancelled) {
[self dismissModalViewControllerAnimated:NO];
}
};
[self presentModalViewController:viewController animated:NO];
//hide the keyboard
[viewController.view endEditing:YES];
}
Also look at this tutorials:
http://www.raywenderlich.com/21558/beginning-twitter-tutorial-updated-for-ios-6
http://mobileorchard.com/ios-tutorial-twitter-integration-in-ios5/
The Social Framework (iOS6) has built-in twitter functionality that will save you some time. In iOS5 there is a (very) similar Twitter Framework.
You need to use OAuth. Read "Getting started with OAuth 2.0" by Ryan Boyd

Resources