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.
Asked
Active
Viewed 449 times
1 Answers
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)
}

choofie
- 2,575
- 1
- 25
- 30