How to post on Facebook wall through an iOS app

Update: This post is outdated. The Facebook has released a newer SDK. For the time being I recommend to take a look at the Facebook documentation at

Making an iPhone or iPad application that allows user to post on his/her Facebook wall sounds really fascinating and exciting, but there is always one question that comes up: How to do that? The major disadvantage of embedding Facebook functionality into an application is the lack of a complete and comprehensive documentation that would help programmers to achieve that. Therefore, I'm writing down my personal experience, after having consumed some time in searching around the web, as well as in trial and error. To clarify the purpose of this post, I'm going to show all the necessary steps that are required to post a message on your Facebook wall. For that reason, I'm going to use an example application, the FBTestApp.

Before starting making the application, there are a few things that must be cleared. There are some preparatory steps that should have been completed before you start writing any code at all. In brief, the following are the necessary steps that should be done to make your app work correctly:

  1. Have a Facebook account! I don't think that anyone have any doubts on that step.
  2. Go to and create a new application. Probably some kind of verification of your account may be needed, don't get stuck on that. If Facebook asks you so, verify your account and proceed. This step is mandatory, because just right after you create your app you'll get a unique application ID. That ID is going to be your passport for the Facebook - Land! If you don't obtain it, there is no way to manage to see your iOS app connecting to Facebook.
  3. Download the facebook-iOS-SDK and add it into your project.
  4. Setup the login/logout mechanism to Facebook account through your app.
  5. Write the magic code that allow you (as well as your users) to connect to Facebook and post messages through your app!

The last two steps are just coding. There is some good stuff to read as well (and you should do so) if you want to get more familiar with what we're going to do here. The Facebook documentation is pretty good to let you understand about the login mechanism (the Single Sign On - SSO) and how application work on Facebook generally, as well as some articles all around the Internet. But as I already said, it's hard to find something to guide you from the beginning until the end.

Let's get started.

First we’ll create the test application and let it stay and waiting for us until we’re ready to use it. So, go and create a new application in XCode. Just create a single view application and name it FBTestApp, no matter what version of XCode you are using (personally, I'm using XCode 4.2). If you are using the XCode 4.2 version, make sure you avoid checking the three options at the bottom of the window:

Go directly to Interface Builder and create something similar to the next image:

At the top place a button with no title, below it a label and almost in the center of the view another button with the title “Publish on Facebook now!”.

One more thing before we go any further. Create a new group in your project and name it “FBConnect”. Don’t tell me that you don’t know what a group is?

At this point just save and leave your app sitting on the XCode.


If you don't already have a Facebook account then you're in the wrong place. Go and create one!


  • Go to to create an application (also, you'll find there all the necessary documentation for the Facebook part). An explanatory note: When saying create an application on Facebook I mean that you just declare your application and set its options if you want.
  • Select the "Build For Mobile" option.
  • Click on the "Apps" link at the top of the page.
  • Login if you are asked to and if you are not already logged in to your Facebook account.
  • Click on the "+ Create New App" button.
  • Enter a name for your application. That name is going to be public, so make sure that you choose a good name.
  • Type the security code and you'll be guided into the basic settings window of your newly created application.
  • At the top of the window you'll see the App ID. That's what you need!

You may also take a look at the rest of the application’s options if you wish so. Look also on the left of the window for some iOS examples and tutorials. For now, our job here is done,  so just keep (copy and paste) the App ID somewhere to use it later and move on.

Our next task is to get the facebook-iOS-SDK which contains all the necessary libraries to get us connected to Facebook. Go to and download the SDK.

After having it downloaded, open the facebook-ios-sdk.xcodeproj with the XCode, while having your application already opened. Pay attention now. Open the FBConnect group at the left of the window and select all files (and group) inside it. Now with the selected files, drag and drop into the FBConnect directory (group) you created earlier inside your project. Make sure to check the “Copy items into destination group’s folder (if needed)” option in the popup window! For XCode 4  users, if dragging and dropping from one project to another cannot be done, then while being in your project open the menu File-->Add files to “FBTestApp”..., look up for the downloaded SRC directory and add or drag the files into your project, inside the FBConnect group.

STEP 4, 5

The real work is starting now! Before you continue, make sure that you have fully understood how the login/logout Facebook mechanism works. I’ll give you an idea here, but read the Single Sign On tutorial in any case.

The general idea of the Single Sign-On mechanism is to keep the user connected into his/her account even after the application is terminated. That is based on the logic that normally a device (iPhone, iPad, or anything else) is used by one person only (the device owner), so there is no reason to have the user logging in each time that wants access to Facebook. After having logged in once, the credential data (username and password) are not asked again, unless the user signs off the account! This is managed by saving an access token and an expiring date in the user defaults settings of the application. As long as that access token is valid there is no need to login again. When it gets invalidated (after a logout for example) then the user credentials are required again.

The Facebook SDK is responsible to provide the login window. We’ll do nothing on that matter! Depending on your device and the iOS version you use, the login window will appear either as a popup window inside your application, or the Safari browser will load until you get connected and then automatically will get disappeared and you’ll get back to your application. In the meanwhile, in both of the two ways, after you get logged in your application will acquire the access token that will keep you connected even after you terminate the application.

In general, programmatically we have to implement the next stuff (not necessarily with the order they appear):
  • Create a Facebook object that will handle all the Facebook-part job and that will allow us to get and send data from and to Facebook.
  • Create methods to save and load the access token info from the user defaults.
  • Implement all the Facebook delegate methods that handle the responses to our requests.
  • Implement the standard methods that will allow us to define what is going to happen after every login or logout.
  • Create a method that will assign the appropriate login/logout images to the login button, depending on the user connection state.
  • Implement a method to start and stop an activity view to notify the user that the app is busy.
  • Create the IBActions that will trigger all the actions.

Go to the XCode now. Leave the application’s delegate header file as it is:

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>{

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;

and go directly to the delegate .m file. Leave also here everything as it is:

@implementation AppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

-(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
   self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
  self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;

- (void)dealloc
    [_window release];
    [_viewController release];
    [super dealloc];


and add the next two methods which are quite important. They both do the same thing, but they are needed as they serve different versions of the iOS.

// This method will be used for iOS 4.2 version and prior.
-(BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    return [[_viewController facebook] handleOpenURL:url];

// This method will be used for iOS versions grater than 4.2.
- (BOOL)application:(UIApplication *)application openURL:(NSURL*)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [[_viewController facebook] handleOpenURL:url];

In those methods, you might need to replace the _viewController object with the correct object name in XCode version prior to 4.

Those methods will respond to the openURL call that will be made by the Facebook login window.

Note this: Because the _viewController (FBTestAppViewController) is the one and only view controller in this application, it's declared and initialized automatically by the XCode and that's why we didn't touch the delegate's header file or anything else. Nevertheless, if you are going to use another view controller other than that to implement the Facebook functionality, then you should manually create an object of that view controller in the delegate's header file, synthesize it and init it inside the delegate's .m file and finally in the two methods above, replace the _viewController object with the new one you will have created. Clear?

Let’s go now to the ViewController.h (FBTestAppViewController.h) file. Modify it and make it look like the next one:

#import <UIKit/UIKit.h>
#import "FBConnect.h"
#import "Facebook.h"

@interface ViewController : UIViewController <FBSessionDelegate, FBRequestDelegate, FBDialogDelegate>{
    UIButton *btnLogin;
    UIButton *btnPublish;
    UILabel *lblUser;
    UIActivityIndicatorView *actView;

    Facebook *facebook;
    NSArray *permissions; 
    BOOL isConnected;    

@property (retain, nonatomic) IBOutlet UIButton *btnLogin;
@property (retain, nonatomic) IBOutlet UIButton *btnPublish;
@property (retain, nonatomic) IBOutlet UILabel *lblUser;
@property (retain, nonatomic) UIActivityIndicatorView *actView;
@property (retain, nonatomic) Facebook *facebook;
@property (retain, nonatomic) NSArray *permissions;
@property (nonatomic) BOOL isConnected;

- (IBAction)LoginOrLogout;
- (IBAction)Publish;


Go to the ViewController.m (FBTestAppViewController.m) file and synthesize the properties we declared just right above:

@implementation ViewController
@synthesize btnLogin;
@synthesize btnPublish;
@synthesize lblUser;
@synthesize actView;
@synthesize facebook;
@synthesize permissions;
@synthesize isConnected;

Also you should import the following above the synthesize:

#import "FBConnect.h"
#import "Facebook.h"

At this point open the Interface Builder and make all the necessary connections.

Inside the viewDidLoad method add the next content:

- (void)viewDidLoad
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    // Set the permissions.
    // Without specifying permissions the access to Facebook is imposibble.
    permissions = [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", nil] retain];
    // Set the Facebook object we declared. We’ll use the declared object from the application
    // delegate.
    facebook = [[Facebook alloc] initWithAppId:@"YOUR_APP_ID" andDelegate:self];
    // Check if there is a stored access token.
    [self checkForPreviouslySavedAccessTokenInfo];
    // Depending on the access token existence set the appropriate image to the login button.
    [self setLoginButtonImage];
    // Specify the lblUser label's message depending on the isConnected value.
    // If the access token not found and the user is not connected then prompt him/her to login.
    if (!isConnected) {
        [lblUser setText:@"Tap on the Login to connect to Facebook"];
    else {
        // Get the user's name from the Facebook account. The message will be set later.
        [facebook requestWithGraphPath:@"me" andDelegate:self];
    // Initially hide the publish button.
    [btnPublish setHidden:YES];

Don't forget to add your app ID in the next line and replace the YOUR_APP_ID string:

facebook = [[Facebook alloc] initWithAppId:@"YOUR_APP_ID" andDelegate:self];

Inside the viewDidLoad method we used a couple of methods that do not exist yet. Let’s add them. Go ABOVE the viewDidLoad and add the two methods we used:

    // Initially set the isConnected value to NO.
    isConnected = NO;
    // Check if there is a previous access token key in the user defaults file.
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] &&
        [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
        // Check if the facebook session is valid.
        // If it’s not valid clear any authorization and mark the status as not connected.
        if (![facebook isSessionValid]) {
            [facebook authorize:nil];
            isConnected = NO;
        else {
            isConnected = YES;

Next method:

    UIImage *imgNormal;
    UIImage *imgHighlighted;
    UIImageView *tempImage;
    // Check if the user is connected or not.
    if (!isConnected) {
        // In case the user is not connected (logged in) show the appropriate
        // images for both normal and highlighted states.
        imgNormal = [UIImage imageNamed:@"LoginNormal.png"];
        imgHighlighted = [UIImage imageNamed:@"LoginPressed.png"];
    else {
        imgNormal = [UIImage imageNamed:@"LogoutNormal.png"];
        imgHighlighted = [UIImage imageNamed:@"LogoutPressed.png"];
    // Get the screen width to use it to center the login/logout button.
    // We’ll use a temporary image view to get the appopriate width and height.
    float screenWidth = [UIScreen mainScreen].bounds.size.width;    
    tempImage = [[UIImageView alloc] initWithImage:imgNormal];
    [btnLogin setFrame:CGRectMake(screenWidth / 2 - tempImage.frame.size.width / 2, btnLogin.frame.origin.y, tempImage.frame.size.width, tempImage.frame.size.height)];
    // Set the button’s images.
    [btnLogin setBackgroundImage:imgNormal forState:UIControlStateNormal];
    [btnLogin setBackgroundImage:imgHighlighted forState:UIControlStateHighlighted];
    // Release the temporary image view.
    [tempImage  release];

So far so good. Let’s add a couple more methods that we’ll use later. They concern the activity view that should be displayed while the user’s post is uploaded. Keep in mind that in such crucial times like uploading the user should be prevented from closing the view or doing anything else.

    // Show an alert with a message without the buttons.
    msgAlert = [[UIAlertView alloc] initWithTitle:@"My test app" message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    [msgAlert show];
    // Show the activity view indicator.
    actView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0, 0.0, 40.0, 40.0)];
    [actView setCenter:CGPointMake(160.0, 350.0)];
    [actView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
    [self.view addSubview:actView];
    [actView startAnimating];

    [actView stopAnimating];
    [msgAlert dismissWithClickedButtonIndex:0 animated:YES];

One more thing that we should do as a preparatory step. We’ll create a method that will store the access token info into the user defaults after the users logs in to the Facebook account.

    // Save the access token key info into the user defaults.
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];

Now let’s implement the necessary Facebook delegate methods:

-(void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response {
    // Keep this just for testing purposes.
    NSLog(@"received response");

-(void)request:(FBRequest *)request didLoad:(id)result{
    // With this method we’ll get any Facebook response in the form of an array.
    // In this example the method will be used twice. Once to get the user’s name to
    // when showing the welcome message and next to get the ID of the published post.
    // Inside the result array there the data is stored as a NSDictionary.    
    if ([result isKindOfClass:[NSArray class]]) {
        // The first object in the result is the data dictionary.
        result = [result objectAtIndex:0];
    // Check it the “first_name” is contained into the returned data.
    if ([result objectForKey:@"first_name"]) {
        // If the current result contains the "first_name" key then it's the user's data that have been returned.
        // Change the lblUser label's text.
        [lblUser setText:[NSString stringWithFormat:@"Welcome %@!", [result objectForKey:@"first_name"]]];
        // Show the publish button.
        [btnPublish setHidden:NO];
    else if ([result objectForKey:@"id"]) {
        // Stop showing the activity view.
        [self stopShowingActivity];
        // If the result contains the "id" key then the data have been posted and the id of the published post have been returned.
        UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"My test app" message:@"Your message has been posted on your wall!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [al show];
        [al release];

Pretty important method! Everything that gets back as an answer from the Facebook should be handled in there!

We should always handle the case that our request fails:

-(void)request:(FBRequest *)request didFailWithError:(NSError *)error{
    NSLog(@"%@", [error localizedDescription]);
    // Stop the activity just in case there is a failure and the activity view is animating.
    if ([actView isAnimating]) {
        [self stopShowingActivity];

That's all we need from Facebook delegate methods. It's time to take care about what is going to happen on login, logout, e.t.c.

Firstly, when the user logs in to the Facebook account we need to save the access token info and then get the user's name from the account.

    // Save the access token key info.
    [self saveAccessTokenKeyInfo];
    // Get the user's info.
    [facebook requestWithGraphPath:@"me" andDelegate:self];

Then, manage the login cancel action.

    // Keep this for testing purposes.
    //NSLog(@"Did not login");
    UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"My test app" message:@"Login cancelled." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [al show];

When the user logs out?

    // Keep this for testing purposes.
    //NSLog(@"Logged out");
    // Hide the publish button.
    [btnPublish setHidden:YES];

We’re fine until now. But how do we trigger all the above? Let’s implement the IBActions.

- (IBAction)LoginOrLogout {
    // If the user is not connected (logged in) then connect.
    // Otherwise logout.
    if (!isConnected) {
        [facebook authorize:permissions];
        // Change the lblUser label's message.
        [lblUser setText:@"Please wait..."];
    else {
        [facebook logout:self];
        [lblUser setText:@"Tap on the Login to connect to Facebook"];
    isConnected = !isConnected;
    [self setLoginButtonImage];

- (IBAction)Publish {
    // Show the activity indicator.
    [self showActivityView];
    // Create the parameters dictionary that will keep the data that will be posted.
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"My test app", @"name",
                                   @"", @"link",
                                   @"FBTestApp app for iPhone!", @"caption",
                                   @"This is a description of my app", @"description",
                                   @"Hello!\n\nThis is a test message\nfrom my test iPhone app!", @"message",              
    // Publish.
    // This is the most important method that you call. It does the actual job, the message posting.
    [facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];

Before you test your application there is one final step that should be done.
Add what you see in the following image inside the info.plist file.

Add the entries from URL types and below.

Don't forget to release the objects we declared:

- (void)dealloc {
    [btnLogin release];
    [lblUser release];
    [btnPublish release];
    [actView release];
    [facebook release];
    [permissions release];
    [super dealloc];

We're now almost ready. There are a couple of issues that should be resolved if you're using the XCode 4.2 IDE.
First of all, if there is warning with message:

No previous prototype for function ...
you should follow the next steps to face it:

  • Select the project.
  • Select Build Settings.
  • Make a search for the word "prototype".
  • In the "Missing function prototypes" key change the value from YES to NO.
Secondly, if you see a bunch of errors after you insert the Facebook SDK, then do these:
  • Select the project.
  • Select Build Settings.
  • Make a search for the words "reference counting".
  • In the "Objective-C Automatic Reference Counting" change the value from YES to NO.
Normally, all errors and warnings should be gone now. If the XCode keeps reporting errors or warnings, then just try to figure out a solution or make a search in the web. Somebody else would have found a solution for sure.

By looking both at the code and in the project's files, you may wonder where are the images we use for the login button. These images should exist in the Facebook SDK files, but obviously they don't. I found them in an older SDK and you may get them here. Download the zip file, uncompress it and add the images into your project.

Please make sure that you read about the Facebook SDK, the Graph API, the Single Sign-On (SSO) and the other existing techonologies about the Facebook, if you want to move any further from this example. Read also about the requests and dialogs to get an understanding of the code we used above.
Here are some links:

Apart from the above links that I identically provide, navigate in the site to find more stuff and tutorials to read.

Last note: you might want to specify the iOS Deployment Target inside the project settings to make the app running to a specific iOS version (and above probably).

You are now ready to run the application!
Once you login, the Facebook will ask you if you want to allow the application to access your Facebook account. Allow it. When you’ll get back in your app, you’ll see that the login button turns into a logout one, and the prompt message is changed and welcomes the user. The publish button also is now visible. Tap on it and go check your wall on Facebook.

That post is just a beginning to help you start from somewhere when you need to add Facebook functionality into your iOS application. Of course, you should do your own search and read more about all that stuff.

I hope you get some help through this post!
Keep coding!

You may download the project here.

NOTE (Jun 20, 2012)
The sample code has been tested on XCode 4.3.2 and in iOS 5.1 and it works correctly.
The only think you should always have in mind is to create an app into the Facebook Developers, get the app's ID and set it into the project (both in code and in the .plist file). If the app ID is not correct or it's not set then the sample code won't work.
Finally, this is the code that I use in my apps to post messages into the Facebook, so be assured that it works.


  1. Hi facebook now ignores the @message, is there any way to post from an ultextfiled?

  2. Why did you avoid the ARC tick when you were creating the project. I know there's an issue adding the FBConnect to a project with ARC support. I thought you were posting a workaround for it

  3. my application gets sstuck on please wait

  4. application crashes on [facebook logout:self]

  5. If your app gets stuck on the "please wait" message then make sure that your app connects to the Internet.
    The "please wait" goes away when the app gets a response from the web server.

  6. Hi, is there any chance you could post the whole xproj. I have read this about 6 times now and cannot get it to work. thanks

  7. You can download the project now, just look at the end of the post.

  8. Thank you Gabriel,

    you're really awesome.


  9. Really great guide!!
    I need to ask you something... I had to import the facebook API like static library otherwise i had lot of error.
    But in static library the class are different there isn't implementation of the method. Do i have to rewrite them?


  10. Thanks a lot...
    If you do everything according to the tutorial everything works fine. Have you followed all the steps correctly? If you drag and drop the facebook files from the downloaded project from the github or use the file-->add... then it works. Are you doing something else wrong inside your project? You can also download the test project. It's at the end of the tutorial. Make sure to follow carefully steps 3, 4 and 5 (especially step 3).

  11. my application gets stuck on please wait .... in 5.1 Simulator.
    Please help ;)))

  12. Thanks gabrielth,
    tonight i will try again all the process and i will lwt you know! ;)


  13. Hey gabrielth,
    i tried again. I find the problem. The difference is that i use the automatic reference counting. Do you know how i can use your guide also if i have the automatic reference guide activated?


    1. Dear Marco, to be honest I've never tried to connect on Facebook having the ARC activated. Actually, I didn't have the time to find a workaround, but at the first chance I'll try to find a solution. If you can develop your app and keep the ARC off, then do it. Trust me that I'll look for a solution but I don't know when I'll have some results due to time pressure.

      Thank you too and forgive me if I don't find the time to answer on time!

    2. Gabrielth don't worry about that!! Thanks a lot for your time... But i will try to solve the problem and if i do it i will give you a feedback!

      Nothing to forgive!! ;)

      Take care!


  14. Nice Post,It's working fine... Keep up the good work..
    If you can please try to post a project with You tube Api


  15. Hi Gabrielth!

    Thanks for your post, it really helped me!
    I have actually had ARC switched on for my project. I just had to remove the "retain" parts from your code (Xcode actually alerted me to do so), and I did not need to release the objects either.
    One thing I missed from your description is that you define the msgAlert as an instance variable after the synthesize part in the ViewController.m file.
    And my first run was not successful because I forgot to add the pcitures for the button... After that, it was working perfectly!

    I played a bit with the Publish method to replace the requestWithGraphPath with dialog, but then I also had the "Please Wait..." error in my app.

    Again, I am really thankful for this example! It was not easy to find one that does not break ;)


  16. Quick question: I've tried to run this tutorial and remove all non-ARC references, but when I try to launch the app it just shows a black screen and won't launch. There aren't any warnings either. But I keep getting the Thread 1: Program received signal: "SIGABRT". Which I assume is because something's not initializing correctly.

    Anyone else tried to do this without using ARC and had success?

    1. Nevermind, I figured it out. I just restarted my computer, downloaded the new xcode, and put -fno-objc-arc in the properties of the Facebook ios sdk files. Works like a charm. Thanks for the tutorial.

  17. Hi,
    Thanks for the tutorial.
    Although i've registered 3 apps with Facebook,
    only the first one works.
    Any ideas why that might be?
    It's only the App ID I'm changing in the sample code.
    There doesn't appear to be any other link between the actual iOS app
    and the app registered with Facebook.
    Cheers, Art.

  18. Can this be done in landscape. I tried implementing these buttons and label in landscape mode. However once i pressed the login button, it shows a Facebook dialogue which appears to be portrait. Can this dialogue be change to landscape? I am trying out on device orientation meaning for portrait, one view for landscape, will be another view which holds all the Facebook stuff.

  19. I already saw the succeeded alert. But I can't find the post in the feed.... What's wrong?

  20. How to use the same code that uses the same Facebook ID? The Url scheme takes me the the wrong App because they share the same URL. Great tut thanks! :-)

  21. Hi am using your blog it's very beneficial for me but i had a problem in it that when i launch it in my iphone(3.1.3) then it opens a dialog for login and for username password but i does'nt want that dialog. I want that the app takes login information from facebook app as you also described. I am using xcode version(3.2.5) and ios 4.2.
    Please suggest me what to do.

  22. hi i am using this post but the app stuck on Please wait.... and i also checked my internet connection it works properly still it stucks there please help me out

  23. hi this post is working properly in the simulator but when i upload my app into the device it display an alert that "My test app Login Cancelled" why? i am not able to understand why it occurs. i am testing in iphone version 5.1.1

    1. I have the same problem. And I found that on iPhone app is using Face app to login but somehow it is not working. On simulator there is no face app and it uses Safari. When I deleted Face app on iPhone it worked. Now I have to figure out how to force login via Safari even if face app is installed

  24. Can this facebook integration can be done in Xcode 3.2.5 version.
    Please do reply me.

    1. Well my friend, I guess it could be used in XCode 3.2.5, but it also depends on the iOS SDK you use. I really cannot say as I haven't tried it in XCode 3.2.5. I'm really sorry I can't help you, you just have to try.
      By the way, why don't you download a newer version of XCode? It's much easier to work with.

  25. Nice post for a beginner but have to deal with the Facebook integration stuff! Thank you so much. If I have any question I will post here. Thanks!

  26. I used the Xcode 4.32 and I used your sample code. After I clicked the Facebook login, it showed me "An error occurred. Please try again later." After I click "Okey", it took me to my Facebook Newsfeed page. I don't understand why. Please do reply me. Thanks.


    1. Dear friend,
      these days I'm away from my computer, therefore I can't check it out or reproduce the situation you describe. I'll get back on my computer on a couple of days, so I'm going to look at it then. At this point, I'd recommend you at first to check the code once again. If everything looks OK, don't hesitate to play around with the code and experiment with it. If you find your way, please post it here for someone else who might encounter this problem. Otherwise, I'll try to find a solution as soon as possible.

    2. Thanks Gabrielth! I found the problem is common but no one provides any solution for that. I just made two changes in your sample code: first change the appID in code and also in the .plist file. I checked the setting for arc and others are the same.


  27. For those who stucks at Please wait.... When you download the project if you use different verison of xcode you possibly get error at (strong). If you change this strongs with retain, and in main.m if you get error @autopoolrelease you should just change code inside of main .m with "NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    [pool release];"

    I have done this steps and know sample code is working, how ever if I integrate the code with my app (tab bar controller app) it stucks at Please wait... again. Good tutorial though it at least helped me to understand whats going on


  28. Hey,
    I'm stuck at the Please wait... and I can't get it to work. I think it has to do with the url response. Can somebody help please?

  29. Response to above post : but a break point at appdelegate.m where return handle openurl see if you get access token or not

  30. I got the error message as"Safari can not open the page because address is invalid" when I click on okay.Please tell me where I did wrong.

    1. Well, I've come up with this issue once. Try to delete the app from the Simulator, then open Safari (on Simulator again) and delete all open pages. After the two previous steps, re-run the app on the Simulator.
      This way worked for me. I hope it works for you too.

    2. Hello rani, You are getting this error because you didnt inlclude your App id into pList file.Please check that.

  31. This comment has been removed by the author.

  32. I want to know how can i post message on a particular group wall? Can anybody please help me?

  33. Hello gabrielth. nice article. It help a lot. But i am facing one issue with logout. I have downloaded code from here and added my appid at both the place. Code works fine for login and posting on wall but am not able to logout from the facebook to authenticate another user credentials. Also i have tried it putting two separate button for login and logout still it is not working. do you have any idea why is it show ? can you please help me for this ?

  34. Wow your post is such a big help! It can be quite difficult to get into the technical side of using your gadget to enjoy Facebook, but the steps you provided are just helpful and easy! Much thanks!

  35. Hi Gabrielth,
    I have used your code in my project and there is no warning and no error in the project and my app, However, it stucks at Please wait... . Moreover, when I checked in the log I got this error "facebookErrDomain error 10000" I have also googled it and try to workout Different things such as setting parameters , App Id and so forth but any of didn't work. Now, I have more than 1 view controller and I have follow all your instructions but unfortunately its not working(And I think its only this bit that is cozing me the trouble ). If you can please suggest me for this wud be great help.


  36. Hello my friend.
    Well, I should say, with heavy heart, that this post is a little bit outdated. You see, Facebook has released new SDK and a few things are now different, especially with the new iOS 6.0 that supports Facebook integration.

    What I would suggest you right now to is to visit the website and follow the instructions in there (instructions for Mobile apps). You'll have to download the SDK 3.1 and follow by letter the documentation. Thankfully, the Facebook documentation has been improved and if you stick with it I'm sure you'll find your way easily.

    I'm about to write a new post about the new Facebook SDK, but I can't tell you to wait for it as I don't really know when I'll have it ready.

    I wish you luck...

    1. Hi Gabrielth,
      Thanks for the response.
      I know I can achieve it from the developer's link but the thing is if I implement it by using sdk 3.1 it won't work for ios 4-5 I mean it doesn't have backward compatibility and I don't want to do that. thats all.
      Thanks Anyways..

    2. I don't know if that helps you, but if you take a look at this:

      there is a note which says that you can set to 'OPTIONAL' the iOS 6-specific frameworks if you want to have the SDK work for older versions of operation systems.

      Personally, I embedded the SDK 3.1 in a new project that runs on iOS 5.1 and I want it to have compatibility with the iOS 6 too. I just set to 'Optional' the Social.Framework, AdSupport.Framework and Accounts.Framework according to the documentation and it worked.

      I hope this may help you even a little. Don't get disappointed. It's the Facebook that it changed the way our apps get connected to it.

      I hope you find your way...

  37. Please can you confirm the version of the FaceBook SDK used for this tutorial. It would be useful to put this information in the title for the article.


  38. Hi! this is a good post. But can you help me how i will post comment on particular post id? (I am having the post id).

  39. i want to integrate Facebook latest version 3.1.1 in Xcode 4.5.1 it will works the same procedure u posted........

  40. Hai,Could you please tell me ,how to post the image through simulator in facebook

  41. This is a great ideas and tips of programming codes..Thanks a lot for sharing..

    SEC email retention requirements

  42. Example poroject link is broken!!!

    The page cannot be found!
    The page you have requested cannot be found on this server.
    HTTP 404 - File Not Found

  43. Wow....very good example you share here, it's help me lots in my project, I am also developing social media app for iPhone. Thank you very much you saved my lots of time.

  44. I am trying my hand in game development for iPhone. I am finding some difficulty in writing code for some parts, could you please provide me more codes! ~great article though~

  45. Very helpful tips on how to post on facebook wall through.

  46. We have some world class programmer. If you need any help for you programming, please visit & learn more.

  47. Hi,
    This post is very nice and interesting.