简体   繁体   中英

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];
    }}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM