6
votes

I have implemented a UIActivityViewController, for sharing some information. In this case I have a question: Is it possible to make a different text between the facebook sharing/twitter sharing/ or mail sharing? That the text which is set is different from the others...

A good UIActivityViewController tutorial would be very useful.

My code at the time is, for displaying text and image:

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

But how can I manage it that the NSString is just for the mail, and make a seperate NSString for the facebook share option?

Any suggestions?

Thanks.

3

3 Answers

13
votes
4
votes

You can have your class conform to the UIActivityItemSource protocol and implement activityViewController:itemForActivityType:. The activityType will be FB, Twitter, Messages app, etc, so you can do a switch on it and return a different object based on the activity.

-2
votes
-(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];

    }

}