如何快速共享图像和文本? [英] How to share both Image and Text together in swift?

查看:89
本文介绍了如何快速共享图像和文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试快速共享图像和文本.但是,当我选择通过Facebook,Messenger或whatsapp进行共享时,它仅显示文本(不共享图像).我正在使用UIActivityViewController进行共享.

I am trying to share both image and text in swift. but when i choose to share via facebook, messenger or whatsapp it only gives text (image is not shared). I am using UIActivityViewController for sharing.

这是我的代码:

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代码正在为我工​​作.还附有两种方法的屏幕截图.

Below is UIActivityViewController code is working for me. also attached screen shot for both the methods.

 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示例的屏幕截图:

Screen shot for UIActivityViewController example :

使用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示例的屏幕截图:

Screen shot for SLComposeViewController example :

希望它将对您有帮助.

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

Do let me know if you have any query.

这篇关于如何快速共享图像和文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆