ActivityViewController图像共享无法正常工作

ActivityViewController图像共享无法正常工作

本文介绍了Swift UIActivityViewController图像共享无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UIActivityViewController 来分享图片。在WhatsApp最近的更改允许共享后,我能够在共享选项中看到WhatsApp。我正在分享图像和消息,我可以看到短信,但我无法共享图像。相同的代码适用于Viber,FB,Twitter等。不确定WhatsApp我缺少什么。

I am using UIActivityViewController to share image. After the WhatsApp recent changes to allow share i am able to see WhatsApp in the share option. I am sharing an image and message, I can see the text message but i am not able to share images. The same code works fine with Viber, FB, twitter etc., Not sure what i am missing for WhatsApp.

func shareImage() {
    var messageStr:String  = "Check out my awesome photo!"
    var img: UIImage = currentPhoto!

    var shareItems:Array = [img, messageStr]

    let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
    activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeCopyToPasteboard, UIActivityTypeAddToReadingList, UIActivityTypePostToVimeo]

    self.presentViewController(activityViewController, animated: true, completion: nil)

}


推荐答案

分享文字||图片试试这个 Swift

func share(shareText shareText:String?,shareImage:UIImage?){

    var objectsToShare = [AnyObject]()

    if let shareTextObj = shareText{
        objectsToShare.append(shareTextObj)
    }

    if let shareImageObj = shareImage{
        objectsToShare.append(shareImageObj)
    }

    if shareText != nil || shareImage != nil{
        let activityViewController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = self.view

        presentViewController(activityViewController, animated: true, completion: nil)
    }else{
        print("There is nothing to share")
    }
}

分享这样的电话:

let imageToShare = UIImage(named: "myImage")
share(shareText: "Sharing this text", shareImage: imageToShare)

这篇关于Swift UIActivityViewController图像共享无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 23:26