如何使用UIActivityViewController在Facebook和Twitter上共享不同的文本?

时间:2014-05-16 13:13:37

标签: ios objective-c uiactivityviewcontroller

在我的应用程序中,我使用UIActivityViewController Facebook Twitter 中共享文本。但如何分享不同的文字?请提前帮助..谢谢

我使用了这段代码:

NSString *posturl2=@"twittwrer and facebook ";


UISimpleTextPrintFormatter *printData = [[UISimpleTextPrintFormatter alloc]
                                             initWithText:@"Hi"];


NSArray *Itemsarray = @[posturl2,printData];

UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:Itemsarray                                                                              applicationActivities:nil];


[self presentViewController:activityController
                       animated:YES completion:nil];

想要这样

enter image description here

1 个答案:

答案 0 :(得分:-2)

导入社交框架

#import <Social/Social.h>

然后致电

- (void)shareOnFacebookWithText:(NSString *)textToShare {
    if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
        SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

        [controller setInitialText:textToShare];
        [self presentViewController:controller animated:YES completion:nil];
    }
}

- (void)shareOnTwitterWithText:(NSString *)textToShare {

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
    {
        SLComposeViewController *tweetSheet = [SLComposeViewController
                                               composeViewControllerForServiceType:SLServiceTypeTwitter];
        [tweetSheet setInitialText:textToShare];
        [self presentViewController:tweetSheet animated:YES completion:nil];
    }
}