// How to post to user Facebook Wall in iOS 4 & 5 – Easy Mode – Guilmo

How To postToFacebook

Published on February 20th, 2013 | by Guilherme Mogames


How to post to user Facebook Wall in iOS 4 & 5 – Easy Mode

I spent a lot of time trying to find some code to simply post a status to a user Facebook Wall, but all the code that I found required me to integrate with the Facebook API, do all the Login integrations and all the other stuff.

But I just wanted a simple way for a user to simply share my app link on his Facebook Wall. And after a long time I found an external library that does all the dirty work for you.

– “But .gm. what’s the catch?”

No Catch, just a simple detail, this library was made to be used in games to post a High Score to a user Facebook Wall, I just changed the default sharing text to the text I wanted to share, removing the High Score.

So let’s start the How To!

  1. Go to Facebook Developers website and create your Facebook App (https://developers.facebook.com/apps)
  2. After the application is created, go to “Select how your app integrates with Facebook“, choose Native iOS App and type the Bundle ID exactly as you did on the XCode project. If you have your App Store ID, you can fill the fields, otherwise leave it blank. Leave all other options disable.
    Facebook App Integration
  3. Download the FacebookScorer from github – https://github.com/tonisalae/FacebookScorer
  4. Add the FacebookScorer folder to your project (drag the folder from Finder to your XCode).
  5. Since FacebookScorer does not work with ARC, we need to tell XCode not to check for ARC in the library files, so go to Build Phases and expand the Compile Sources section. In there you will see all the files from FacebookScorer/ and FacebookScorer/FBConnect. Select all of those files and press “return” on your keyboard. That will open a blank popover, in there, type “-fno-objc-arcwithout the quotes and hit “return” one more time.
    -fno-objc-arcThat will set the No ARC flag for XCode and will fix all the Warnings and Issues found.
  6. Open FacebookScorer/FacebookScorer.m and edit the following lines with you Facebook App ID and custom sharing info.
    static NSString* kAppId = @"291589097636434"; // Your Facebook app ID here
    #define kAppName        @"Guilmo.com"
    #define kCustomMessage  @"I highly recommend checking guilmo.com website for the best iOS tips and tutorials."
    #define kServerLink     @"http://www.guilmo.com"
    #define kImageSrc       @"http://www.guilmo.com/wp-content/uploads/2013/02/default_guilmo.png"
  7. Now find the string (around line 123)
    NSString *customMessage = [NSString stringWithFormat:kCustomMessage, highscore, kAppName];

    And Replace it with

    NSString *customMessage = kCustomMessage;

    That will remove the High Score sharing from the post.

  8. Open your AppDelegate.m file, #import FacebookScorer/FacebookScorer.h in the header and add this piece of code
    - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
        return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url];
    // For 4.2+ support
    - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
        return [[[FacebookScorer sharedInstance] facebook] handleOpenURL:url];

    This will make sure that the Facebook application is opened when your app calls it.

  9. Open your Info.Plist file and add “URL Types” array as shown below (click on the + sign in any of the items on the list to create a new line).
    You will need to introduce your Facebook’s App ID (the same one you used in the FacebookScorer.m file) in the “URL identifier” and “URL Schemes” fields. Notice the “fb” prefix in “URL Schemes”, use it like the image below!.
  10. And that’s it for the configuration.

All the steps above was to configure everything necessary. Don’t be scared, it’s really simple!

Now let’s make it work!

  1. Open your ViewController .m file and import FacebookScorer in the header
    #import "FacebookScorer/FacebookScorer.h"
  2. Inside your function or in a Button action put this complex piece of code [sarcasm mode=off]
    [[FacebookScorer sharedInstance] postToWallWithDialogNewHighscore:0];

    (don’t know how to create buttons? Check my other post clicking here)

  3. Notice that the method is called postToWallWithDialogNewHighscore and I pass a 0 value. Right here it doesn’t matter what number you put in, because we removed the High Score sharing in the previous steps.
  4. Build & Run and be happy!
    Post to Facebook


Possible Problems:

– If after allowing the app to post on your behalf in the Facebook window you get a blank white screen, make sure you Added both functions inside the AppDelegate.m file and that the Facebook App ID is correct inside the Info.Plist file and in the FacebookScorer.m file.

– If you get any Facebook errors, make sure you created the App correctly and enabled the Native iOS Mode with the same Bundle ID you have in your project.

– My project is not building, I’m getting some Error and Warning messages! Check out if all files from FacebookScorer have the “-fno-objc-arc” flag. You may have missed one file.

– Have a different one? drop the bomb in the comments so we can help you.

Thanks Toni Sala for creating this awesome code.

Do you have any questions, comments, compliments? hit the comments below.



Tags: , , , , ,

About the Author

Founder of the Guilmo.com website and freelance iOS developer for over 2 years. Creator of one of the most used financial app in Brazil and also creator of the iPhone game FlyingMoo. Over 10 years of experience with IT and over 4 years as a Scrum Master for a large multinational IT company.

One Response to How to post to user Facebook Wall in iOS 4 & 5 – Easy Mode

  1. arti says:

    thanks your code is working fine but i have some problem.
    [[FacebookScorer sharedInstance] postToWallWithDialogNewHighscore:0];
    the text hellos set before the Facebook sharing but i want that text would set after sharing

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to Top ↑