Ionic 3 Beginner: How to add Social Sharing using ionic-native

Social Sharing allows you to share content ranging from text, images, links and video to embedding data feeds and even creating full blown applications based exclusively on social media content. Today we will learn about How to add Social Sharing using ionic-native in your Ionic 2 or ionic 3 application.

I will show you how you can add social sharing to you Ionic 2 Apps using ionic-native. We will add social sharing for Twitter, Facebook, WhatsApp and a general Sharing Option as well. In this post, we will start from scratch and we will be using the blank template in Ionic 2.

We will be able to achive

A button that opens your phone’s share sheet and let’s you pick the app you’ll use to share.

A fab collection that opens up sharing via sms, whatsapp or facebook.

Lets code the application for – Ionic 3 Beginner: How to add Social Sharing using ionic-native

We will start off by creating out project with the blank template. –v2 option in ionic start is now optional.

$ ionic start ionic3Share blank
$ cd ionic3Share

Now we’re going to install Social Sharing native plugin. You can find the entire docs to the plugin in the ionic-native docs.

Now we can have multiple ways of using social sharing, the first one is Shares using the share sheet. When Shares using the share sheet is used, your application opens the native sharing options on your android device.

So to use Shares using the share sheet, lets create a button in home.html file and corresponding handler in the home.ts file

Other options are you directly share via SMS, Whattsapp, Facebook and email. To demonstrate that lets create a collection of FAB buttons, which when clicked, swipes out to provide sharing options. Documentation for fab collection can be found here – http://ionicframework.com/docs/components/#fabs

Summary

This concludes our post – Ionic 3 Beginner: How to add Social Sharing using ionic-native.

Thanks to Ionic Native (and the awesome developers who contribute their time and effort to create such fantastic plugins) adding the ability to share content across different social media platforms is incredibly simple.