Todd Pleeter
Todd Pleeter

Reputation: 69

Call a function located on Facebook sdk from another viewcontroller

I am pretty new at programming, so please don't burn me too bad. I downloaded the Hackbook version for Facebook. However, I have a number of view controllers that will use the 'share this' button but I don't know how to do it. I know that I want to use the functions that are already in place.

@implementation ViewConcertsViewController
...

-(IBAction)shareThis:(id)sender{
[appDelegate.facebook authorize:nil delegate:self];
                APICallsViewController *apiViewController = [[APICallsViewController alloc] initWithNibName:nil bundle:nil];
                [apiViewController shareButton];
}

Then in my APICallsViewController, I have:

-(void)shareButton{
[self performSelector:@selector(//what do I put in here!!!!)];
}

Thank you in advance.

This is what I did:

@implementation ViewConcertsViewController
...
-(IBAction)shareThis:(id)sender{
    APICallsViewController *apiViewController = [[APICallsViewController alloc] initWithNibName:nil bundle:nil];
    [apiViewController shareButton:sender];
}


@implementation APICallsViewController
...
-(void)shareButton:(id)sender{
    SEL selector = NSSelectorFromString(@"getAppUsersFriendsNotUsing");
    if ([self respondsToSelector:selector]) {
        [self performSelector:selector];
    }
}

Thank you.

Upvotes: 1

Views: 169

Answers (1)

Pareshkumar
Pareshkumar

Reputation: 176

Looks like you just need to change up the method in the Hackbook Sample in the APICallsViewController.


/*
 * Dialog: Feed for friend
 */
- (void)apiDialogFeedFriend:(NSString *)friendID {
    currentAPICall = kDialogFeedFriend;
    SBJSON *jsonWriter = [[SBJSON new] autorelease];

    NSArray* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           @"Get Started",@"name",@"http://m.facebook.com/apps/hackbookios/",@"link", nil], nil];
    NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
    // The "to" parameter targets the post to a friend
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   friendID, @"to",
                                   @"I'm using the Hackbook for iOS app", @"name",
                                   @"Hackbook for iOS.", @"caption",
                                   @"Check out Hackbook for iOS to learn how you can make your iOS apps social using Facebook Platform.", @"description",
                                   @"http://m.facebook.com/apps/hackbookios/", @"link",
                                   @"http://www.facebookmobileweb.com/hackbook/img/facebook_icon_large.png", @"picture",
                                   actionLinksStr, @"actions",
                                   nil];

    HackbookAppDelegate *delegate = (HackbookAppDelegate *)[[UIApplication sharedApplication] delegate];
    [[delegate facebook] dialog:@"feed"
                      andParams:params
                    andDelegate:self];

}

But if you looking to send an AppRequest (not the same thing as share button on a webpare) then checkout - (void)apiDialogRequestsSendTarget:(NSString *)friend

So what do you want to share? A status update, a photo, a link to a URL, a Facebook app request there is. Lot to share so it's kind of hard to know where you want to go. [limk]http://developers.facebook.com/docs/reference/iossdk/request/. And hers [link]http://developers.facebook.com/docs/reference/dialogs/ there are 7 default one-two line code to share stuff

There are currently 7 Dialogs available for you to use:

** -The Feed Dialog allows a user to post a story to their Timeline and to their friends' News Feeds

-The OAuth Dialog allows a user to authorize an application as part of an authentication flow.

-The Add Page Tab Dialog allows a user to add an application to a Facebook Page which they administer.

-The Friends Dialog allows a user to send a friend request to another user.

-The Pay Dialog allows a user to make a purchase using Facebook Credits.

-The Requests Dialog allows a user to send a request to one or more of their friends

-The Send Dialog allows a user to send a Facebook Message to one or more of their friends. **

But if you can give more details of the tasks it will make it easier to provide help and samples. For my expierence setting up application project in xcode to use the fb sdk with your custom app Id from apple and Facebook is the hard part. I would highly reccomend starting a Xcode project from scratch. It will take a bit more but once you set up an app from start to logged-in and have friends data via FBRequest you will be able to move very fast.

Starting from an sample app you will always have stuff in the background going on you can't fix or improve or really use the API like you want.

Upvotes: 1

Related Questions