iOS:向本机 iPhone 应用程序添加 Facebook Like 按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8110393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:21:56  来源:igfitidea点击:

iOS: Adding a Facebook Like button to a native iPhone app

iosfacebookbuttonfacebook-like

提问by AndroidDev

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 Like 按钮添加到本机 iPhone 应用程序。在应用程序中,用户浏览商业目录或交易。当他们点击某个项目以查看详细信息时,最好有一个 Facebook Like 按钮,可用于将项目发布到用户的 Facebook 页面。

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

Facebook 写道:“目前,Like 按钮仅在移动网络应用程序中可用”。

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.

我的应用程序是本机应用程序而不是网络应用程序,因此我认为这是不可能的。但是,我确实假设可以在屏幕上混合使用本机 UI 组件和 Web 组件,因此可能可以实现 Like 按钮,尽管我不确定您如何将数据从本机部分传递到 Web 部分.

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.

如果唯一的解决方案是 hack,那么我不会实施它,因为在某些时候,当 Facebook 更改他们的 API 时,hack 将失败。

回答by Oded Ben Dov

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

稍微阅读一下,你会得到很多线索。这是一个: 在 iOS 应用程序中喜欢按钮

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

一个评论指向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://angeloloqui.blogspot.com/2010/11/facebook-like-button-on-ios.html

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

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...

但不确定您是否获得了本机 UIButton。也许你可以在后台打开一个 webview 并模拟点击它......

GL, update if you have some findings, Oded.

GL,如果您有一些发现,请更新,Oded。

回答by Mawoon

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

现在您可以使用以下代码使用 FBlike 按钮,但它需要下载最新的 sdk 并且它是测试版:(

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];

回答by Nate

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

看起来 Facebook 最终决定通过 Open Graph API 更直接地允许这样做。

See documentation here

请参阅此处的文档

回答by LolaRun

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

看看这个,FB 只是通过他们的 SDK 使它成为可能。目前仅用于测试和 ios

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

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