Facebook & Twitter share button stopped working [c

2019-09-17 10:52发布

问题:

Recently I had it working, but now it just stopped out of nowhere. The buttons do nothing when they are pressed. Thhe code doesn't even give breakpoint or errors. What is wrong?

Download Project (3.2mb)

- (IBAction)ShareFB
{
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
    {
        slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
        [slComposeViewController addImage:[UIImage imageNamed:@"logo-carrito.png"]];
        [slComposeViewController addURL:[NSURL URLWithString:@"http://www.google.com"]];
        [self presentViewController:slComposeViewController animated:YES completion:NULL];
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No FB Account" message:@"There are no FB account registered. Configure one" delegate:nil cancelButtonTitle:@"Dissmiss" otherButtonTitles:nil];
        [alert show];
    }
}

- (IBAction)ShareTW
{
    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
    {
        slComposeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
        [slComposeViewController addImage:[UIImage imageNamed:@"logo-carito.png"]];
        [slComposeViewController addURL:[NSURL URLWithString:@"http://www.google.com"]];
        [self presentViewController:slComposeViewController animated:YES completion:NULL];
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No TW Account" message:@"There are no TW accounts registered. Configure one." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
        [alert show];
    }
}

回答1:

In your storyboard, your first scene has its class set to ViewController, but in actually it should obviously be one of the classes included in your project, e.g. Tab1_ViewController.