Skip to main content

Adding the Facebook Like Button in an iPhone App



Does anyone know how I would include a facbeook "like button" in an iphone app. I tried calling the iframe inside of a uiwebview but that doesn't work.




Comments

  1. Check out this nice bit of code:
    http://angelolloqui.blogspot.com/2010/11/facebook-like-button-on-ios.html

    Add the FBLikeButton class to your view:

    FBLikeButton *likeButton = [[FBLikeButton alloc] initWithFrame:CGRectMake(0, 372, 320, 44)
    andUrl:@"http://www.facebook.com/pages/De-Zilk/108209735867960"];


    Thanks a lot Angel García Olloqui

    EDIT: Nice to add... For bonus points:
    If you use above method the webpage is not well formatted for an iPhone. What you can do is run some JavaScript code to remove all the disturbing divs. Use this (long sentence):

    [_webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"javascript:document.getElementsByClassName('uiButton')[2].style.visibility='hidden';var child1 = document.getElementById('standard_status');var parent1 = document.getElementById('login_form');parent1.removeChild(child1);var child2 = document.getElementById('pageheader');var parent2 = document.getElementById('booklet');parent2.removeChild(child2);document.getElementById('loginform').style.width = '200px';var child3 = document.getElementById('reg_btn_link');var parent3 = document.getElementsByClassName('register_link')[0];parent3.removeChild(child3);var child4 = document.getElementById('signup_area');var parent4 = document.getElementById('login_form');parent4.removeChild(child4);var child5 = document.getElementsByClassName('mbm')[0];var parent5 = document.getElementById('loginform');parent5.removeChild(child5);var child6 = document.getElementsByClassName('reset_password form_row')[0];var parent6 = document.getElementById('loginform');parent6.removeChild(child6);var child7 = document.getElementsByClassName('persistent')[0];var parent7 = document.getElementById('loginform');parent7.removeChild(child7);"]];


    You can place it in the delegate method webViewDidFinishLoad from the FBDialog Facebook class.

    ReplyDelete
  2. You can include it in a UIWebView, just make sure it's inside <html><body>. The problem is that once the user clicks the button, the UIWebView may redirect to a log-in form, so you would have to make it large enough to fit that thing.

    Have fun creating a design that presents the button in a sensible fashion.

    ReplyDelete
  3. Several of the solutions above (e.g. @floorjiann, @fabiobeta, @Stephen-Darlington, @scott) assume that the iPhone application is also a Facebook application (with its own id).

    However if your iPhone application just has a fan page, this is not the case.

    ReplyDelete
  4. maybe this is helpful

    http://www.raywenderlich.com/1626/how-to-post-to-a-users-wall-upload-photos-and-add-a-like-button-from-your-iphone-app

    ReplyDelete
  5. Facebook have recently updated their iPhone Facebook Connect framework to work with the Graph API. This is the API that you need to "Like" objects on Facebook.

    ReplyDelete
  6. I this moment in time you can't. The mobile APIs are not exposing this capability.
    You can use some workaround consisting in embedding the html way of doing it in your app.

    Some details on the workaround here: http://petersteinberger.com/2010/06/add-facebook-like-button-with-facebook-connect-iphone-sdk/

    ReplyDelete
  7. Here you go - w the source code...enjoy -and please leave a comment if its useful.

    http://nowbranded.com/blog/adding-a-facebook-like-button-to-an-iphone-application/

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex