对于 iOS 8,Pinterest 有一个分享扩展。如何设置图片来源 URL 和描述属性?我正在使用 UIActivityViewController。我是否使用 UIImage、用于 sourceURL 的 NSURL 和用于描述和返回的 NSString 创建自定义类?我不确定 Pinterest 如何知道设置源 URL 和描述。
问问题
425 次
1 回答
0
假设您正在子类share
上实现一个方法UIViewController
,下面的代码应该符合您的期望:
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];
}
斯威夫特 (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)
}
于 2017-04-25T10:35:43.653 回答