iOS: Adding a Facebook Like button to a native iPh

2019-03-08 21:32发布

I would like to know whether it is possible to add a Facebook Like button to a native iPhone app. In the app, the user browses a business directory or deals. When they tap on an item to view the details, it would be nice to have a Facebook Like button that can be used to post the item to the user's Facebook page.

Facebook writes: "Currently, the Like button is only available in mobile web apps".

My app is a native app and not a web app, so therefore I assume it's not possible. However, I do assume that it is possible to mix native UI components on a screen along with web components and therefore it might be possible to implement the Like button, although I am not sure how you pass data from the native portion to the web portion.

If the only solution is a hack, then I won't implement it because at some point the hack will fail when Facebook alters their API.

4条回答
迷人小祖宗
2楼-- · 2019-03-08 22:12

Now you can use the FBlike button using the following code but it need to download latest sdk and it is the beta version :(

Here is the code:

[FBSettings enableBetaFeature:FBBetaFeaturesLikeButton];
[FBSettings enablePlatformCompatibility:NO];
FBLikeControl *like = [[FBLikeControl alloc] init];
like.objectID = @"http://shareitexampleapp.parseapp.com/photo1/";
like.likeControlHorizontalAlignment=FBLikeControlHorizontalAlignmentRight;
like.likeControlStyle=FBLikeControlStyleBoxCount;
[self.view addSubview like];
查看更多
Viruses.
3楼-- · 2019-03-08 22:22

read around SO a little, you get many leads. Here's one: Like button in iOS application

And a comment points to github.com/brow/FacebookLikeView

It has same caveats, but it seems there aren't any magic solutions.

There are these blogposts as well:

http://angelolloqui.blogspot.com/2010/11/facebook-like-button-on-ios.html

http://petersteinberger.com/2010/06/add-facebook-like-button-with-facebook-connect-iphone-sdk/

But not sure you get a native UIButton. Maybe you can open a webview in the background and emulate a click on it...

GL, update if you have some findings, Oded.

查看更多
霸刀☆藐视天下
4楼-- · 2019-03-08 22:26

Check this out, FB just made it possible through their SDK. Only for testing and ios for now

https://developers.facebook.com/docs/ios/like-button/

查看更多
姐就是有狂的资本
5楼-- · 2019-03-08 22:31

It looks like Facebook finally decided to allow this, more directly, via the Open Graph API.

See documentation here

查看更多
登录 后发表回答