How to set Pinterest sourceURL and description using UIActivityViewController with Pinterest.sharextension

For iOS 8 Pinterest has an access extension. How to set image source url and description attributes? I am using UIActivityViewController. Create custom class with UIImage, NSURL for sourceURL and NSString for description and return? I do not know how Pinterest will know how to set the source URL and description.

+4
source share
1 answer

Assuming you implement a method sharein a subclass UIViewController, 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)
}

: enter image description here

0

All Articles