2
votes

I've to integrated the FB SDK 3.1 in my ios application.

I successfully share an image on my wall, but i'm not able to set the "via [appname]" (it takes by default "via ios"). I've already put in my info.plist file the appid value.

I'm also not able to make the sharing work for ios5 (it replies with Error 400).

Following there's the code i use:

- (void)viewDidLoad{

appDelegate = [[UIApplication sharedApplication]delegate];
if (!appDelegate.session.isOpen) {
    appDelegate.session = [[FBSession alloc] init];

    if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
        [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                         FBSessionState status,
                                                         NSError *error) {
        }];
    }
}

and when i have to share, i call this method:

- (IBAction)fbShare:(id)sender {
if (appDelegate.session.isOpen) {

    BOOL displayedNativeDialog = [FBNativeDialogs presentShareDialogModallyFrom:self
                                                                initialText:textView.text
                                                                      image:img
                                                                        url:nil
                                                                    handler:nil];
    if (!displayedNativeDialog) {
        [self performPublishAction:^{

        [FBRequestConnection startForUploadPhoto:img
                               completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                               }];
    }];}

} else {
    if (appDelegate.session.state != FBSessionStateCreated) {
        appDelegate.session = [[FBSession alloc] init];
    }

    [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                     FBSessionState status,
                                                     NSError *error) {
    }];}
}

- (void) performPublishAction:(void (^)(void)) action {
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound) {
    [FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                               defaultAudience:FBSessionDefaultAudienceFriends
                                             completionHandler:^(FBSession *session, NSError *error) {
                                                 if (!error) {
                                                     action();
                                                 }
                                                 else{
                                                 }

                                             }];
} else {
    action();
}}

Any hint?

Thanks a lot,

erica

1
Looks like this is not possible yet facebook.stackoverflow.com/questions/12801424/…MrBr

1 Answers

1
votes

I successfully share an image on my wall, but i'm not able to set the "via [appname]" (it takes by default "via ios"). I've already put in my info.plist file the appid value.

Most likely you've not set the Facebook app name. I'd recommend looking it at https://developers.facebook.com/apps admin panel