与 iOS 6.0 原生 Facebook 集成共享:“通过我的应用名称发布”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12547616/
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
Sharing with iOS 6.0 native Facebook integration: "Posted via my app name"?
提问by Alex G
I have just integrated facebook into my app via ios 6 but I have an issue when posting on my wall. It simply says "post via ios app". I want it to say "posted via the app name". I have made an app identity with facebook and I have the app number they have assigned but I am not sure how to integrate this with facebook integration.
我刚刚通过 ios 6 将 facebook 集成到我的应用程序中,但是在我的墙上发帖时遇到了问题。它只是说“通过 ios 应用发布”。我希望它说“通过应用程序名称发布”。我已经与 facebook 建立了一个应用程序标识,并且我有他们分配的应用程序编号,但我不确定如何将其与 facebook 集成进行集成。
Below is my code. If anyone could help, it would be appreciated. Thanks!
下面是我的代码。如果有人可以提供帮助,将不胜感激。谢谢!
{
NSString *message;
message= [[NSString alloc] initWithFormat:@"I've earned %@ points", [self retrieveScore]];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:message];
[controller addURL:[NSURL URLWithString:@"http://mysite"]];
[self presentViewController:controller animated:YES completion:Nil];
[message release];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
NSString *output= nil;
switch (result) {
case SLComposeViewControllerResultCancelled:
output= @"Action Cancelled";
NSLog (@"cancelled");
break;
case SLComposeViewControllerResultDone:
output= @"Post Succesfull";
NSLog (@"success");
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Facebook" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
}
回答by Daniel
UPDATE - it can be done
更新 - 它可以完成
So the Digg for iOSapp is able to share to Facebook without using the Accounts framework to get user permissions... They use UIActivityViewController
and have the post appear as "via Digg", I contacted someone from Digg and they told me that it's a manual process, you must have your iOS app published in the Apple App Store and also have your Facebook application accepted and published in the Facebook App Store.
Then Facebook can manually process linking the two in this way.
因此,iOS应用程序的Digg无需使用帐户框架即可共享到 Facebook 以获取用户权限......他们使用UIActivityViewController
并让帖子显示为“通过 Digg”,我联系了 Digg 的某个人,他们告诉我这是一本手册在此过程中,您必须在 Apple App Store 中发布您的 iOS 应用程序,并在 Facebook App Store 中接受和发布您的 Facebook 应用程序。那么 Facebook 就可以通过这种方式手动处理将两者链接起来。
The obvious downside to this is that UIActivityViewController
meant that you can share from your app without any integration with Facebook, no need for a Facebook app... But to get "via Your App Name" you will need a Facebook app that Facebook will approve into their own app store, once everything is live, you'll need to contact developer relations to link it all up.
这样做的明显缺点UIActivityViewController
是,您可以在不与 Facebook 任何集成的情况下从您的应用程序共享,不需要 Facebook 应用程序...他们自己的应用程序商店,一旦一切都上线,您需要联系开发人员关系以将其全部链接。
Note that the rest of my answer (my previous answer) is correct, the solution is a manual process that Facebook can do for you, your iOS code shouldn't be affected.
请注意,我的其余答案(我之前的答案)是正确的,解决方案是 Facebook 可以为您执行的手动过程,您的 iOS 代码不应该受到影响。
Previous Answer and workaround
上一个答案和解决方法
The native Facebook integration you want is actually the composer view controller. This is obtained by using the SLComposeViewController
class with service type SLServiceTypeFacebook
.
您想要的原生 Facebook 集成实际上是 Composer 视图控制器。这是通过使用SLComposeViewController
具有服务类型的类获得的SLServiceTypeFacebook
。
This class only provides a one way communication and as you notice, you are the one confirming any wall posts by tapping the Post button. This view controller is owned by the iOS system, not your app. And by interacting with this compose view controller you are actually bypassing your application.
该课程仅提供一种单向交流方式,正如您所注意到的,您是通过点击“发布”按钮来确认任何墙上帖子的人。这个视图控制器归 iOS 系统所有,而不是你的应用。通过与这个 compose 视图控制器交互,你实际上是在绕过你的应用程序。
Users like to do this because it gives them security.
用户喜欢这样做是因为它给了他们安全。
Unless your application functions only by a deeper, two-way Facebook integration you should use the SLComposeViewController
(deeper integration meaning your app needs your friends list or existing wall posts, albums etc...).
除非您的应用程序仅通过更深层次的双向 Facebook 集成来运行,否则您应该使用SLComposeViewController
(更深层次的集成意味着您的应用程序需要您的朋友列表或现有的墙贴、相册等......)。
In order for a post originating from your application to appear on Facebook with the "via xxxx" and not "via iOS", you need to interact with Facebook via the SLRequest
class. In order to do this you must also interact with the Account.framework
in addition to Social.framework
.
为了使源自您的应用程序的帖子以“via xxxx”而不是“via iOS”出现在 Facebook 上,您需要通过SLRequest
类与 Facebook 进行交互。为了做到这一点,你还必须与交互Account.framework
除了Social.framework
。
It resembles the previous Facebook iOS SDK previously used (and still can use) in terms of setting it up, you get a reference to the Accounts store of the device, you request for Facebook accounts and send your Facebook app ID and an array of permissions.
在设置方面,它类似于之前使用(并且仍然可以使用)的 Facebook iOS SDK,您可以获得对设备帐户存储的引用,您请求 Facebook 帐户并发送您的 Facebook 应用程序 ID 和一系列权限.
If granted you may then interact with the Facebook Graph API via the SLRequest
class. By posting to your wall in this manor you will have the desired "via xxx".
如果获得批准,您可以通过SLRequest
该类与 Facebook Graph API 进行交互。通过在这个庄园的墙上张贴,您将拥有所需的“通过 xxx”。
To use this please check out the documentation for SLRequest.
Please note that you are responsible for creating your own compose view in this case.
请注意,在这种情况下,您有责任创建自己的撰写视图。
You can of course inspire yourself from the native UI, also check out iPhoto's iOS app, try sharing to Facebook with that app, you will notice it requests permission to interact with your Facebook account (something that does not occur when using SLComposeViewController
), it then presents something very close to the SLComposeViewController
for Facebook post composing.
您当然可以从本机 UI 中激发自己的灵感,也可以查看 iPhoto 的 iOS 应用程序,尝试使用该应用程序分享到 Facebook,您会注意到它请求与您的 Facebook 帐户进行交互的权限(使用时不会发生这种情况SLComposeViewController
),然后呈现与SLComposeViewController
Facebook 帖子撰写非常接近的东西。
But if you look closer you'll notice it is not the same. This also goes for Twitter and their native app vs native integration. They have their own compose view, it's really interesting to note they use the native iOS integration (the Apple frameworks). We know this because going to Settings > Privacy > Twitter you can see Twitter app is an authorised app using the Twitter account(s) on the device.
但如果你仔细观察,你会发现它不一样。这也适用于 Twitter 及其本机应用程序与本机集成。他们有自己的撰写视图,注意到他们使用原生 iOS 集成(Apple 框架)真的很有趣。我们知道这一点,因为转到“设置”>“隐私”>“Twitter”,您可以看到 Twitter 应用程序是使用设备上的 Twitter 帐户的授权应用程序。
Same goes for Facebook.
Facebook 也是如此。
If you don't get permission then you have no way of publishing as your app - aka "via myApp".
如果您没有获得许可,那么您将无法发布为您的应用程序 - 也就是“通过 myApp”。
Sorry to let you down, I also had been searching a way to integrate an ACAccount
into the SLComposeViewController
but couldn't find the way either. Which is a shame... because the native UI is sweet.
很抱歉让你失望,我也一直在寻找一种将 an 集成ACAccount
到 中的方法,SLComposeViewController
但也找不到方法。这是一种耻辱......因为本机用户界面很甜蜜。
回答by docchang
I ended up using a custom Facebook framework with the new Facebook SDK 3.1. Facebook Compose View
我最终在新的 Facebook SDK 3.1 中使用了自定义 Facebook 框架。 Facebook撰写视图
The original is here: facebook compose view. I've just fixed a few minor warnings and updated with the new FB SDK 3.1.
原文在这里:facebook compose view。我刚刚修正了一些小的警告,并与新的FB SDK 3.1更新。
Usage:
用法:
DEFacebookComposeViewControllerCompletionHandler __block completionHandler = ^(DEFacebookComposeViewControllerResult result) {
[self dismissViewControllerAnimated:YES completion:nil];
switch (result) {
case DEFacebookComposeViewControllerResultCancelled:
NSLog(@"Facebook Result: Cancelled");
break;
case DEFacebookComposeViewControllerResultDone:
NSLog(@"Facebook Result: Sent");
break;
}
};
DEFacebookComposeViewController * compose = [[DEFacebookComposeViewController alloc] init];
[compose setInitialText:self.shareText];
[compose addImage:self.shareImage];
[compose addURL:self.shareURL];
[compose setCompletionHandler:completionHandler];
[self presentViewController:compose animated:YES completion:^{}];
Setup:
设置:
- Open the project and do a clean build.
- Go into the folder
$PROJECT_FOLDER\build\Debug-iphonesimulator
and drag both theFBComposeView.framework
&FBComposeView.bundle
into your project.
- 打开项目并进行干净的构建。
- 进入文件夹
$PROJECT_FOLDER\build\Debug-iphonesimulator
并将FBComposeView.framework
&FBComposeView.bundle
拖到您的项目中。
Note: Be sure to use the ones in the Debug-iphonesimulator
. It is the fat binary.
注意:请务必使用Debug-iphonesimulator
. 它是胖二进制文件。
回答by Vilém Kurz
We solved similar problem with iOS 5 Twitter integration, and the result is:
我们用 iOS 5 Twitter 集成解决了类似的问题,结果是:
When posting to Twitter with a dev build or via the simulator it will almost always show up on Twitter as "via iOS". Once your app is approved and you post from the AppStore build it should show up as posted by "YourAppName on iOS" with a link to the apps appstore page.
当使用开发版本或通过模拟器发布到 Twitter 时,它几乎总是在 Twitter 上显示为“通过 iOS”。一旦您的应用程序获得批准并从 AppStore 版本发布,它应该显示为“iOS 上的 YourAppName”发布的应用程序应用程序页面的链接。
original source (ShareKit issue discussion)
I suppose Apple does the same with Facebook and other social services.
我想苹果对 Facebook 和其他社交服务也是如此。
EDIT: unfortunately this only really worked with Twitter.framework. I think the best explanation and answer is the Daniel's one above. Maybe it is a time to radar it, so that Apple knows, what do we want.
编辑:不幸的是,这只真正适用于 Twitter.framework。我认为最好的解释和答案是上面的丹尼尔。也许是时候对其进行研究了,以便 Apple 知道我们想要什么。
Examples of how to use SLRequest with Facebook are in this SO question
如何在 Facebook 中使用 SLRequest 的示例在此 SO 问题中
EDIT2: filed a radar Bug ID# 12980058. Hopefully they listen...
EDIT2:提交了一个雷达错误 ID# 12980058。希望他们听...