44

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.

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;
      }
Rob
  • 25,984
  • 32
  • 109
  • 155
Alex G
  • 2,299
  • 5
  • 37
  • 54
  • I have a sinking feeling that this isn't supported. I'm very interested to know if it is or not, though. It seems like the other option is to integrate the official Facebook SDK for iOS into your app, but that feels like a lot of work compared to using social.framework. – Rob Sep 23 '12 at 14:37
  • @unforgiven3 Agreed. It takes away from the simplicity that social.framework is supposed to be. All this fuss about integration and then to leave a key marketing feature like that out would be quite disappointing – Alex G Sep 23 '12 at 16:51
  • Yeah, it's disappointing. On the other hand, could you include the name of your app in your message (e.g., after 'I've earned X points')? Perhaps you could set the URL to point to your App Store itms:// link? It probably isn't as great as directly using the Facebook SDK, but it might be a decent workaround. – Rob Sep 23 '12 at 18:14
  • @unforgiven3 Agreed. Same issue here. Very disappointing. – docchang Sep 26 '12 at 17:16
  • Please see my updated answer for the solution. http://stackoverflow.com/a/12605241/662605 – Daniel Jan 23 '13 at 14:24

3 Answers3

70

UPDATE - it can be done

So the Digg for iOS app 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.

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.

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.


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.

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.

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

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.

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.

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

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.

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.

Same goes for Facebook.

If you don't get permission then you have no way of publishing as your app - aka "via 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.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Daniel
  • 23,129
  • 12
  • 109
  • 154
  • 1
    Thanks for the great explanation Daniel. You really provided an in depth answer and I would accept however docchang has provided a workaround with an example. +1 and thanks again – Alex G Sep 27 '12 at 01:51
  • 1
    Really nice insights, Thank you very much Daniel. – Umeumeume Oct 01 '12 at 03:14
  • @Daniel Here is The link WHere you can find how to Use `SLRequest Along With The `Account FrameWork`....... http://www.techotopia.com/index.php/IPhone_iOS_6_Facebook_and_Twitter_Integration_using_SLRequest – Kamar Shad Dec 28 '12 at 06:44
  • You're right ! This is a breakthrough ! I will look into this more ! – Daniel Jan 10 '13 at 18:36
  • Daniel, thanks for the info. However, the DIGG app seems to accomplish using the built-in compose view and having 'via DIGG' appear in their posts. Any thoughts on how they might be doing this? [i had deleted this thinking that i'd misread your post, but then realized the comment was still relevant] – ilyashev Jan 10 '13 at 19:17
  • I thought I was crazy answering no one ! No I don't know how they did it yet, but I'm pretty sure it's all about setting up your app correctly on Facebook.com, and making it a public app is important. – Daniel Jan 10 '13 at 19:39
  • i've been trying to determine if using FBNativeDialog with an FBSession for which your app has explicitly gotten user permissions via the OS would do the trick. doesn't seem to for a dev build. but i wonder if it might work for an app store build as per Vilem's answer below. the hard part is testing that theory. – ilyashev Jan 10 '13 at 21:23
  • No, it's not to do with permissions, I didn't grant DIGG any permissions, it doesn't appear in my iOS Facebook settings or in my facebook online apps. I think it's more to do with your Facebook app being or not being in the new Facebook App Store. – Daniel Jan 10 '13 at 21:29
  • right. it seems that digg found some way to do it without requesting permissions, but i had hoped that using an fbsession opened by the app might allow for the same result. we are willing to ask users for permissions, so this would have suited us. we just want to leverage the built-in compose controller. – ilyashev Jan 10 '13 at 22:58
  • 2
    So this definitely seems like the answer, but Facebook makes it incredibly difficult to find any way to actually get in touch with someone in developer relations directly. Any tips on how to best go about this? – Kevin Lord Sep 02 '13 at 02:53
  • 1
    Does anyone know how to contact Facebook to set this up? – lehn0058 Mar 04 '14 at 14:10
  • I am seconding @lehn0058 , Can any one please tell how to contact Facebook developer relation to link it all up. I am trying to get any other way but not able to find how to contact them. I really really need this thing to happen. Please help. – Kumar Aditya Sep 08 '14 at 07:36
13

I ended up using a custom Facebook framework with the new Facebook SDK 3.1. Facebook Compose View

The original is here: facebook compose view. I've just fixed a few minor warnings and updated with the new 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:

  1. Open the project and do a clean build.
  2. Go into the folder $PROJECT_FOLDER\build\Debug-iphonesimulator and drag both the FBComposeView.framework & FBComposeView.bundle into your project.

Note: Be sure to use the ones in the Debug-iphonesimulator. It is the fat binary. enter image description here

NANNAV
  • 4,875
  • 4
  • 32
  • 50
docchang
  • 1,115
  • 15
  • 32
3

We solved similar problem with iOS 5 Twitter integration, and the result is:

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.

original source (ShareKit issue discussion)

I suppose Apple does the same with Facebook and other social services.

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.

Examples of how to use SLRequest with Facebook are in this SO question

EDIT2: filed a radar Bug ID# 12980058. Hopefully they listen...

Community
  • 1
  • 1
Vilém Kurz
  • 3,401
  • 2
  • 34
  • 43
  • Vilem, was this solution confirmed as actually working? We're running into this issue as well, and would like to avoid having to rejigger our sharing. Thanks! – ilyashev Jan 08 '13 at 18:20
  • Please see my updated answer for the solution. http://stackoverflow.com/a/12605241/662605 – Daniel Jan 23 '13 at 14:24