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