iosswiftuikituiactivityviewcontrollermobile-development

Why am I getting an error while sharing image with WhatsApp via UIActivityViewController?


want to share an UIImage from my app with WhatsApp via the UIActivityController. But the moment I share it, Ill get the following error message:

[u 3F6F03F6-805B-4DF3-B3C5-188EA72B9C0C:m (null)] 
[net.whatsapp.WhatsApp.ShareExtension(24.15.79)] Connection to plugin interrupted while in use.
 let shareButtonAction = UIAction { [weak self] _ in
            if let imageSource = self!.imageView.imageSource{
                let items = [imageSource as AnyObject]
                let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
                ac.excludedActivityTypes = [UIActivity.ActivityType.print, UIActivity.ActivityType.postToWeibo, UIActivity.ActivityType.copyToPasteboard, UIActivity.ActivityType.addToReadingList, UIActivity.ActivityType.postToVimeo]
                    
                self!.present(ac, animated: true)
            }
        }

I've already checked the WhatsApp page, but couldn't figure out how solve this. I couldn't find post to this topic either. Only about how to share image and text together. Had someone this problem already and could help me? Thank you


Solution

  • ok, I could solve it by my self. It seems like you have to convert the UIImage into JPEG Data. I hope this will help someone one days

     if let imageSource = self!.imgview.image{
                let dataImage = imageSource.jpegData(compressionQuality: 1.0)
                let items = [dataImage]
                let ac = UIActivityViewController(activityItems: items as [Any], applicationActivities: nil)