6

我已经实现了一个 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?

有什么建议么?

谢谢。

4

3 回答 3

13

你可以去下面的链接,有一个教程可以帮助你:

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

于 2012-11-04T16:57:03.590 回答
4

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

于 2013-09-11T14:09:40.060 回答
-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];

    }

}
于 2017-06-28T05:20:47.403 回答