Ios 6 facebook login tutorial

In the initial guide that appears, select the Single View Application as the project template, in the Applications category, under the iOS section. Click Next to proceed. Also, make sure that in the Devices drop down menu, the iPhone option is selected.

Integrate Facebook Sign In Button in Your iOS App within 60 Minutes!

Click Next, and in the third and last step of the guide select a directory to save the project and then click on the Create button. This part is very crucial, as it involves the necessary setup needed to be done in both Facebook developers website and Xcode project before writing even a single line of code. In the previous tutorial regarding the Facebook login, I presented in details all the actions you should take, so go in the Preparing the Environment section and follow everything described there step by step.

When you are ready with all the above, you can return here and continue with this tutorial.

2. Set up Your Development Environment

Our goal here is to configure the interface by adding all the necessary subviews to the View Controller scene, and by declaring and connecting all the respective IBOutlet properties. We will work in the Interface Builder, so click on the Main. As you notice, the login button is fully customized and it has nothing to do with the login view , the pre-made login button of the Facebook SDK. For each subview described below, find the appropriate object in the Object Library and drag and drop it in the default view.

Open the ViewController. The name of each property clearly declares its purpose. Add the next line right after the last property declaration:. Finally, head back to the Main. Here are the matches:.

iOS Swift: How to integrate the Facebook Login SDK and getting user's email address

Before we dive into the heart of the topic though, we will perform some code-level setup that will determine the initial state of the app. However it will help you make your project similar to the sample in case you develop following this tutorial step by step.

Integrating Facebook Login in iOS Apps - The Manual Way

In order to do that, we must access the CALayer layer property of it, and set three specific properties of the layer object. In the top of the file add the next line:. The following four lines make the image view rounded, with a white border and 1px thick. Make sure to add them in the viewDidLoad method.

At first, we must declare it in the private class section:. The method definition:. Initially, we want all of the above subviews to be hidden. So, right below the above method call, add the next line:. Note that the activity indicator will be handled separately from the rest of the subviews. The same applies to the status label. Firstly, import the AppDelegate.

The Facebook SDK contains a great number of libraries and classes. Among them, there is one class that is responsible for handling sessions, therefore its job is to handle the login process as well. IBAction method we had previously declared. The first thing we have to consider, is to check whether there is an open session or not. However, prior to implementation, make sure to import the Facebook framework at the top of the ViewController. That might seem strange to you at the moment, but I have two specific reasons to do that:.

Having said that, open the AppDelegate. A simple way to do that is using a notification. So, speaking with code this time, go to the AppDelegate. Here it is:. You see that we initialize a NSDictionary object and we set all the values returned by the completion handler to it. Then, a new NSNotification object is posted, using the custom name SessionStateChangeNotification and the dictionary created right before.

Now, back at the toggleLoginState: IBAction method in the ViewController. Samsung gives us so many reasons to switch. Samsung steps up fitness game with two new wearables. Hyperspektiv app glitches up your photos and videos [Review]. Rap T-shirt designer gives Steve Jobs the hip-hop fashion treatment. Leave a comment. Posted in: News Tagged: Add the following subviews to the View Controller scene:. In order for the two UIView objects to properly work, we must modify their classes and set the Facebook-related ones. Setting these custom classes to the above views is not enough to make them work as expected.

One more touch is required, and that is to make a call to both of these classes in the application: Now, go to the AppDelegate.

  • Integrating Facebook Login in iOS App – The Manual Way;
  • app para mover apps a la sd externa?
  • sony xperia a2 price in india 2015.

Open the ViewController. There is a workaround for that:. Finally, go to the Main. Specifically, be sure to match:. By simply doing all the previous preparation, the login view is ready to work. When the login button will be tapped, the user credentials must be given in order to get authenticated. This can take place in two ways: Either through the Safari app, or through the Facebook app if it is installed on your device note that the Facebook app works only on a real device, not in the Simulator.

Once the login info has been provided, our app must take the control again, but besides that, the Facebook SDK must handle and determine the login process. Therefore, before we give a try to the app, we must add the necessary code that will do the above. First of all, open the AppDelegate. The iOS will call this method after the user has authorized the app through Safari of the Facebook app. In here we will add just one line to let Facebook SDK handle the login result and modify the login view accordingly. Behind the scenes, the authentication token received by Facebook will be persistently stored, and the session state will get changed.

In the next code fragment, you see the necessary code added in the above method that handles the login process:. Additionally, we must take care so all subviews to be hidden until the logged in state is determined, except for the login status label. They should become visible only after a successful login and after their values have been set, otherwise they must remain hidden.

Also, along with the call to this method, we will set the empty string as the login status label text value:. Note that you must add it to the viewDidLoad method:. Build and run the app now for first time. Tap or click on the Login with Facebook button, and be prepared to enter your credentials. In a previous section of the tutorial we talked about test users, so I would advise you to use such an account in order to make your testings. If you have successfully logged in and logged out, then you see that the login view makes it really easy to get connected to Facebook.

In this section, we will add all those required delegate methods that will enable us to know if we are connected or not, and then display or hide the appropriate information. There are four delegate methods that should be implemented in total.

  • sony xperia sp when did it come out?
  • App Overview.
  • How to Integrate Facebook Login in iOS App;

Now, open the ViewController. Simply go to the viewDidLoad: Using it, we can change the hidden state of our subviews, and set the current login status value. Two simple tasks are performed here: The appropriate message is set as the text of the status label, and the rest of the subviews are becoming visible. Now that both the profile picture view and the username label can be shown when we have logged in, they must be assigned with values too.

This will take place to another delegate method, which provides us with the info we want. That method contains a FBGraphUser object as parameter, which actually is a NSDictionary object, and it contains all the public info of the logged in user. Here is the implementation:. I intentionally added a NSLog command in the above method, just to let you see the data contained in the user object. By assigning the id property as the profile ID in the profile picture view, the Facebook SDK downloads the appropriate picture and displays it.

Creating the App

If no user picture has been specified, then the default image of the Facebook user will be used. With the above two delegate methods, we managed to handle case where the user has logged in. Now, we must deal with the log out. Here it is:.