Adama
Adama

Reputation: 1097

ios 6 - Post to Facebook in app not working on device

I have a button that brings up the Facebook ui to make a post, but it doesn't do anything on the device. It works fine in the simulator, but performs no action at all on the phone.

Not sure what I can do to figure out the problem -

Here is my ViewController.h

- (IBAction)postToFacebook:(id)sender;

ViewController.m

- (IBAction)postToFacebook:(id)sender {
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
        [controller setInitialText:@"Posted from IOS App Test -- It works!"];
        [self presentViewController:controller animated:YES completion:Nil];
    }}

Upvotes: 1

Views: 933

Answers (1)

msk
msk

Reputation: 8905

You code is working on simulator because isAvailableForServiceType always returns 1 in Simulator. In device you need to setup a facebook account from settings.

Or better just remove this check

[SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]

With this along with the post sheet an OS alert will appear to notify that account setup is required to post.

Upvotes: 1

Related Questions