TSCAmerica.com
TSCAmerica.com

Reputation: 5377

Social.framework doesn't work for Xcode 6.3.2

As a newbie i wanted to try out Facebook and Twitter Post using objective-c

So i added 2 buttons, added actions to it, also added social framework. When i run the code and click on Tweet or Facebook Buttons nothing happens, am i missing something.I am testing it on Simulator, does that make any difference.

Here is my header file SocialSharingViewController.h

#import <UIKit/UIKit.h>

@interface SocialSharingViewController : UIViewController

- (IBAction)postToTwitter:(id)sender;
- (IBAction)postToFacebook:(id)sender;

@end

Here is my .m file SocialSharingViewController.m

#import "SocialSharingViewController.h"
#import <Social/Social.h>

@interface SocialSharingViewController ()

@end

@implementation SocialSharingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (IBAction)postToTwitter:(id)sender {
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
    {
        SLComposeViewController *tweetSheet = [SLComposeViewController
                                               composeViewControllerForServiceType:SLServiceTypeTwitter];
        [tweetSheet setInitialText:@"Great fun to learn iOS programming"];
        [self presentViewController:tweetSheet animated:YES completion:nil];
    }
}

- (IBAction)postToFacebook:(id)sender {
    NSLog(@"clicked facebook button");
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:@"First post from my iPhone app"];
        [self presentViewController:controller animated:YES completion:Nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

Upvotes: 0

Views: 71

Answers (1)

Tim Johnsen
Tim Johnsen

Reputation: 1491

A few things come to mind:

  • Did you connect the buttons in your .xib to the IBAction methods in your code?
  • Is -isAvailableForServiceType: legitimately returning NO, preventing them from showing?

Upvotes: 1

Related Questions