Initial text and paperclipped-URL for action in UIActivityViewController & UIActivityItemSource?

Posted by Benjamin Kreeger on Stack Overflow See other posts from Stack Overflow or by Benjamin Kreeger
Published on 2012-10-09T21:19:59Z Indexed on 2012/10/09 21:38 UTC
Read the original article Hit count: 308

Filed under:
|
|
|

Finally been making it through Apple's (rather dismal) documentation on the new UIActivityViewController class and the UIActivityItemSource protocol, and I'm trying to send different data sets to different actions called from the activity view. To simplify things, I'm looking at two things.

  1. A Facebook posting action, which should say "Check this out!" and also attach a URL to the post (with that cute little paperclip).
  2. A Twitter posting action, which should say "Check this out, with #hashtag!" and also attach that same URL (with the same paperclip).

Here's the code I've got implemented right now.

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
    if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
        return @"Check this out!";
    } else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
        return @"Check this out, with #hashtag!";
    }

    return @"";
}

- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
    return @"";
}

And then when I set up this activity view controller (it's in the same class), this is what I do.

UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:@[self] applicationActivities:nil];
[self presentViewController:activityView animated:YES completion:nil];

My dilemma is how to attach that NSURL object. It's relatively easy when calling the iOS 6 SL-class posting modals; you just call the individual methods to attach a URL or an image. How would I go about doing this here?

I'll note that instead of returning NSString objects from -activityViewController:itemForActivityType, if I return just NSURL objects, they show up with that paperclip, with no body text in the post. If I return an array of those two items, nothing shows up at all.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ios