-1

所以我有我的应用程序设置与共享操作按钮共享当前 URL 到 Twitter 或 Facebook 但是当我单击 Facebook 按钮时它显示一个 Twiiter 共享表。(Tiwtter 选项工作正常)

在我点击 FACEBOOK 选项后,在 iPhone 上进行测试时,会出现标准的推特分享表。

- (IBAction)social:(id)sender {
    UIActionSheet *share = [[UIActionSheet alloc] initWithTitle:@"Pass on the news!" delegate:self cancelButtonTitle:@"OK" destructiveButtonTitle:nil otherButtonTitles:@"Post to Twitter", @"Post to Facebook", nil];

    //You must show the action sheet for the user to see it.
    [share showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

//Each button title we gave to our action sheet is given a tag starting with 0.
if (actionSheet.tag == 0) {

    //Check Twitter accessibility and at least one account is setup.
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {

        SLComposeViewController *tweetSheet =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet addURL:self.newsItemWebView.request.URL];            //This is setting the initial text for our share card.
        [tweetSheet setInitialText:@"Check out this article I found using the 'Pass'  iPhone app:,  "];

        //Brings up the little share card with the test we have pre defind.
        [self presentViewController:tweetSheet animated:YES completion:nil];

    } else {
        //This alreat tells the user that they can't use built in socal interegration and why they can't.
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't send a tweet right now, make sure you have at least one Twitter account setup and your device is using iOS6 or above!." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }


} else if (actionSheet.tag == 1) {

    //Check Facebook accessibility and at least one account is setup.
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {

        SLComposeViewController *facebookSheet =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
        [facebookSheet addURL:self.newsItemWebView.request.URL];
        //This is setting the initial text for our share card.
        [facebookSheet setInitialText:@"Check out this article I found using the 'Pass'  iPhone app:"];

        //Brings up the little share card with the test we have pre defind.
        [self presentViewController:facebookSheet animated:YES completion:nil];

    } else {
        //This alreat tells the user that they can't use built in socal interegration and why they can't.
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"You can't post a Facebook post right now, make sure you have at least one Facebook account setup and your device is using iOS6 or above!." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }   
}
}
4

1 回答 1

0

您使用actionSheet.tag的将与整个操作表相同。如果您想知道按下了哪个按钮,您应该buttonIndex在 if 语句中使用。

更好的是使用UIActivityViewController.

NSArray *items = @[self.newsItemWebView.request.URL];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
activityViewController.completionHandler = ^(NSString *activityType, BOOL completed) {
    // do any thing you want when the user finishes the share activity.
    // Like present a message that that activity has completed or not.
};

[self presentViewController:activityViewController animated:YES completion:nil];
于 2013-08-20T13:30:14.243 回答