Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share text and image on facebook wall (objective C)

I am working on an app which provides user to share the details of their app into facebook . I have UITableview where it contains the list of author name and when u click on book name it goes to another UITableView where it shows the different book of that author in each TableViewCell. I'm able to display the list in 2nd UITableView . I wanted to know how to share the author name , book name and the image (2nd tableview details). I'm showing the code which does that .. So when the user wants to share the details, he will have to tap on the UIButton which is there in every cell of author UITableView.

didselectatindexpath

    NSDictionary *selectedAuthor = nil;

     NSArray *sectionArray=[mainIndexDictionary objectForKey:[allKeysArray objectAtIndex:indexPath.section]];
        selectedAuthor = [sectionArray objectAtIndex:indexPath.row];
        iPath=[[selectedAuthor objectForKey:@"SymptIndexID"] intValue];
        NSLog(@"iPath - %d",iPath);

        authortitleString=[[selectedAuthor objectForKey:@"authorIndexName"]stringByAppendingString:@" cure!"];
    }


    bookArray=[objDB customCellData:(NSInteger)iPath];
    [self.view bringSubviewToFront:authorView];
    [bookTableView scrollRectToVisible:CGRectMake(0.0, 0.0, 320.0,10.0) animated:NO];

    [bookTableView reloadData]

;
like image 985
raptor Avatar asked Mar 21 '13 16:03

raptor


2 Answers

In ios 6.0 you can achieve as follows (you must add the social framework to your project)

 #import <Social/Social.h>

 - (void)ShareFacebook
 {
    SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
    SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){

        [fbController dismissViewControllerAnimated:YES completion:nil];

        switch(result){
            case SLComposeViewControllerResultCancelled:
            default:
            {
                NSLog(@"Cancelled.....");
               // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];

            }
                break;
            case SLComposeViewControllerResultDone:
            {
                NSLog(@"Posted....");
            }
                break;
        }};


    [fbController setInitialText:@"This is My Sample Text"];


    [fbController setCompletionHandler:completionHandler];
    [self presentViewController:fbController animated:YES completion:nil];
}
else{
    UIAlertView *alert = [[[UIAlertView alloc]initWithTitle:@"Sign in!" message:@"Please first Sign In!" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil]autorelease];
    [alert show];
 }
}
like image 141
umer sufyan Avatar answered Nov 02 '22 11:11

umer sufyan


your question is a bit unclear but you can use this code for publishing text and image to Fb considering you have implemented all the others methods of FB ios Api correctly

SBJSON *jsonWriter = [[SBJSON new] autorelease];

NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                                                       APP_NAME,@"text", fb_app_url,@"href", nil], nil];
NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               APP_NAME, @"name",
                               fb_app_url, @"link",
                               fb_publish_image, @"picture",
                               APP_NAME, @"name",
                               @"Awesome APP", @"caption",
                               [NSString stringWithFormat:@"I am  loving it", GAME_NAME], @"description",
                               @"Get it now!",  @"message",
                               actionLinksStr, @"action_links",
                               nil];

[self.faceBook dialog:@"stream.publish" andParams:params andDelegate:self];

for further details to implement fb api you can see

How to integrate Facebook into iPhone Appenter link description here

this link shows the parameters allowed while publishing a message http://developers.facebook.com/docs/howtos/publish-to-feed-ios-sdk/

like image 43
hariszaman Avatar answered Nov 02 '22 11:11

hariszaman