문제

I'm using the UIDocumentInteractionController method to share images from my app to WhatsApp (explained in How send image to WhatsApp from my application?, WhatsApp image sharing iOS).

I'm also aware of the share via URI option, used to share texts only (explained here: https://www.whatsapp.com/faq/iphone/23559013).

Is there a way to share both an image and a caption in a single share?

도움이 되었습니까?

해결책

Currently there is no way that you can share both image and text together on whatsapp. Sharing both image and text together is not handled from the whatsapp side.

So, at a time you can share only image or text.

다른 팁

from my experience and knowledge "UIDocumentInteractionController" is the only way of doing it for now...

You can use the UIDocumentInteractionController as mentioned in the 2nd answer to this question as of August 4, 2014: Share image/text through WhatsApp in an iOS app

You can share an image + text on whatsapp IFF you share a link along

For both options you will need to store the image somewhere online as the workaround is based on whatsapp's link preview feature

For example can upload the image to a s3 bucket or firebase storage.

Option 1: You can control the shared link response

Using Open Graph tags:

<meta property="og:image" content="http://yourimage_with_complete_URL.png"/>  
<meta property="og:title" content="Your Title"/>  
<meta property="og:description" content="Your description."/>  
  • og:title : Maximum 35 characters.
  • og:description : Maximum 65 characters.
  • og:image : Image(JPG or PNG) of size less than 300KB and minimum dimension of 300 x 200 pixel is advised.

Option 2: You can't control the shared link response

Using firebase dynamic links (or similar service)

Then simply set the image's URL to the socialMetaTagParameters of the Firebase DynamicLinkComponents:

linkBuilder.socialMetaTagParameters = DynamicLinkSocialMetaTagParameters()
linkBuilder.socialMetaTagParameters.title = "Example of a Dynamic Link Title"
linkBuilder.socialMetaTagParameters.descriptionText = "Example of a Dynamic Link descriptionText"
linkBuilder.socialMetaTagParameters.imageURL = "https://www.example.com/my-image.jpg"

Now pass the the created firebase dynamic link to the UIActivityController along with the text you want to share as you usually do. This will display the image in whatsapp using whatsapp's link preview feature along side the passed text.

  • You can choose to shorten the URL.
  • Make sure the created link of the uploaded image is publicly accessible.

Check the firebase documentation for more info.

screenshot example

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top