Avoid Whatsapp Share Only Text in UIActivityViewController


Hello guys, this is a good day to start a new resolution because. It's still fresh 2020, we can start doing something new or something that we want to complete when this year ends. I hope I can always write a new article every week with good quality. Thanks for support to be consistence it's hard and easy to do if you are in perservence mode.

If you ever have installed app called instagram or others social media, you will find a share feature. where you can share your photo to others app. Like email, notes or social media. Fortunately iOS provide the feature to share called UIActivityViewController. So it's like we use library in iOS, we just create our text or photo sending to UIActivityViewController. Then it will create share feature like above.

But I have a problem when trying to share on Whatsapp. It just showed text when I sent image and text. Unfortunely Whatsapp only support image or text, not both of them. So we need to choose what's gonna we share. In my case I need to share image without text, so how do I check when the user share on whatsapp spesificaly.

So I created two classes for each items. SocialActivityItem and TextActivityitem, SocialActivityItem for sharing image and TextActivityitem for sharing text. It will extent UIActivityItemSource so in order to be used in activityItems. If you're confused with what I'm talking about, I will provide the code for you guys. Sorry I'm not expert to explain something :D.

So this is the code guys.


You need to create these two classes SocialActivityItem and TextActivityItem. Then implement it in UIActivityViewController like example above. You can see "If condition" for Whatsapp, it needs to return nil to avoid sending text only. So that's it guys, thanks for visiting. Have a blessed day.

Popular posts from this blog

How to restart the app with flutter Android and iOS

How to have ConstraintLayout inside ScrollView and ScrollView inside ConstraintLayout Android

Missing system image Android Studio solution