4

For iOS 8, Pinterest has an share extension. How do I set image source URL and description attributes? I am using UIActivityViewController. Do I create a custom class with UIImage, NSURL for sourceURL and NSString for description and return? I'm not sure how Pinterest would know to set the source URL and description.

CLDev
  • 1,076
  • 3
  • 12
  • 20

1 Answers1

0

Assuming that you are implementing a share method on a UIViewController subclass, the code below should meet your expectations:

Objective-C

- (void)share {
    NSString *textToShare = @"Hello Pinterest!";
    NSURL *url = [NSURL URLWithString: @"http://blank.org"];
    UIImage *imageToShare = [UIImage imageNamed:@"so-logo"];
    NSArray *activityItems = @[textToShare, url, imageToShare];
    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems: activityItems applicationActivities: nil];

    [self presentViewController: activityViewController animated: YES completion: nil];
}

Swift (3.0.2)

func share() {
    let textToShare = "Hello Pinterest!"
    let url = URL(string: "http://blank.org")!
    let imageToShare = UIImage(named: "so-logo")!
    let activityItems: [Any] = [textToShare, url, imageToShare]
    let activityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)

    self.present(activityViewController, animated: true, completion: nil)
}

And the results should be something like this: enter image description here

choofie
  • 2,575
  • 1
  • 25
  • 30