如何向UIActivityViewController对象添加不同的文本

时间:2012-11-02 22:30:44

标签: iphone objective-c ios

我已经实现了一个UIActivityViewController,用于共享一些信息。在这种情况下,我有一个问题:是否可以在Facebook分享/ Twitter共享/或邮件共享之间制作不同的文本?设置的文本与其他文本不同......

一个好的UIActivityViewController教程非常有用。

我当时的代码是,用于显示文字和图片:

NSString *text = @"Lime Cat";
        UIImage *image = [UIImage imageNamed:@"MyApp Icon 512x512.png"];
        NSArray *items = [NSArray arrayWithObjects:text,image , nil];

但我如何管理NSString仅用于邮件,并为facebook共享选项制作单独的NSString?

有什么建议吗?

感谢。

3 个答案:

答案 0 :(得分:13)

您可以转到下面的链接,有一个可以帮助您的教程:

https://www.albertopasca.it/whiletrue/objective-c-custom-uiactivityviewcontroller-icons-and-text/

答案 1 :(得分:4)

您可以让您的班级符合UIActivityItemSource协议并实施activityViewController:itemForActivityType:activityType将是FB,Twitter,消息应用程序等,因此您可以对其进行切换并根据活动返回不同的对象。

答案 2 :(得分:-2)

-(void)ShareImageandText:(UIButton *)sender    
{

NSString * texttoshare = @“http://qrs.ly/l851gh4”;

UIImage * image = [UIImage imageNamed:@“default”];

    NSString *noteStr = [NSString stringWithFormat:@"Please follow this link below to install the Freedom.desi application on your IPhone. %@",texttoshare];
    NSURL *url = [NSURL URLWithString:texttoshare];

    NSArray *activityItems = @[noteStr,image];

    NSLog(@"this %@",activityItems);

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[noteStr,image] applicationActivities:nil];
        activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePrint];

        [self shareText:noteStr
               andImage:image andUrl:nil];

        [self presentViewController:activityVC animated:TRUE completion:nil];

    }
    //if iPad
    else {
        // Change Rect to position Popover
        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[noteStr, url] applicationActivities:nil];
        activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePrint];

        [self shareText:noteStr
               andImage:image andUrl:nil];

        UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityVC];
        [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    }

}