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

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.