Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
945 views
in Technique[技术] by (71.8m points)

objective c - Sharing with iOS 6.0 native Facebook integration: "Posted via my app name"?

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;
      }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...