当前网络视图iPhone的社交共享url.(Xcode)



所以我的应用程序设置有共享操作按钮,可以将当前URL共享到Twitter或Facebook,但当我单击Facebook按钮时,它会显示Twiiter共享表。(Tiwtter选项运行良好)

在我点击FACEBOOK选项后,在iPhone上测试时,会出现标准的twiter共享表。

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

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

更好的是使用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];

最新更新