gpt4 book ai didi

swift - 如何快速共享图像和文本?

转载 作者:IT王子 更新时间:2023-10-29 05:27:23 25 4
gpt4 key购买 nike

我正在尝试快速共享图像和文本。但是当我选择通过 facebook、messenger 或 whatsapp 分享时,它只提供文字(不分享图片)。我正在使用 UIActivityViewController 进行共享。

这是我的代码:

func displayShareSheet(latitude:NSString?, longitude:NSString?, image:UIImage?, address:NSString? ) {
let activityViewController = UIActivityViewController(activityItems: [(latitude as NSString?)!, (longitude as NSString?)!, (image as UIImage?)!, (address as NSString?)!], applicationActivities: nil)
presentViewController(activityViewController, animated: true, completion: {}
)
}

最佳答案

下面是为我工作的 UIActivityViewController 代码。还附上了这两种方法的屏幕截图。

 func shareImage() {
let img = UIImage(named: "SoSampleImage")
let messageStr = "Ketan SO"
let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: [img!, messageStr], applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeCopyToPasteboard, UIActivityTypeAddToReadingList, UIActivityTypePostToVimeo]
self.presentViewController(activityViewController, animated: true, completion: nil)
}

UIActivityViewController 示例的屏幕截图:

enter image description here

使用 SLComposeViewController 的替代方法:

func share(){
let img = UIImage(named: "SoSampleImage")
let composeSheet = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
composeSheet.setInitialText("Hello, Ketan!")
composeSheet.addImage(img)
self.presentViewController(composeSheet, animated: true, completion: nil)
}

SLComposeViewController 示例的屏幕截图:

enter image description here

希望对你有帮助

如果您有任何疑问,请告诉我。

关于swift - 如何快速共享图像和文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39632365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com