Skip to main content

Social Sharing

The Social Sharing plugin provides the ability to share text, files, images, and links via social networks, SMS, and email.

Installation#

If you have not already setup Ionic Enterprise in your app, follow the one-time setup steps.

Next, install the plugin:

npm install @ionic-enterprise/social-sharing
npx cap sync

Using with AndroidX Projects (Android)#

This plugin relies on the legacy Android Support libraries and will not work in projects using the newer AndroidX libraries without using the jetifier tool to patch them.

npm install jetifier
npx jetifier

To run it automatically when dependencies are installed, add "postinstall": "jetifier" in the package.json.

Index#

Classes#


Classes#

SocialSharing#

SocialSharing:

name: Social Sharing

description: Share text, files, images, and links via social networks, sms, and email.

For Browser usage check out the Web Share API docs: https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin#5-web-share-api

usage:

import { SocialSharing } from '@ionic-enterprise/social-sharing/ngx';
constructor(private socialSharing: SocialSharing) { }
...
// Check if sharing via email is supported
this.socialSharing.canShareViaEmail().then(() => {
// Sharing via email is possible
}).catch(() => {
// Sharing via email is not possible
});
// Share via email
this.socialSharing.shareViaEmail('Body', 'Subject', ['recipient@example.org']).then(() => {
// Success!
}).catch(() => {
// Error!
});

canShareVia#

canShareVia(appName: string, message?: string, subject?: string, image?: string, url?: string): Promise<any>

Checks if you can share via a specific app.

Parameters:

NameTypeDescription
appNamestringApp name or package name. Examples: instagram or com.apple.social.facebook
Optional messagestring-
Optional subjectstring-
Optional imagestring-
Optional urlstring-

Returns: Promise<any>


canShareViaEmail#

canShareViaEmail(): Promise<any>

Checks if you can share via email

Returns: Promise<any>


saveToPhotoAlbum#

saveToPhotoAlbum(fileOrFileArray: string | string[]): Promise<any>

Save an array of images to the camera roll

Parameters:

NameTypeDescription
fileOrFileArraystring | string[]Single or multiple files

Returns: Promise<any>


setIPadPopupCoordinates#

setIPadPopupCoordinates(targetBounds: string): void

defines the popup position before call the share method.

Parameters:

NameTypeDescription
targetBoundsstringleft, top, width, height

Returns: void


share#

share(message?: string, subject?: string, file?: string | string[], url?: string): Promise<any>

Shares using the share sheet

Parameters:

NameTypeDescription
Optional messagestringThe message you would like to share.
Optional subjectstringThe subject
Optional filestring | string[]URL(s) to file(s) or image(s), local path(s) to file(s) or image(s), or base64 data of an image. Only the first file/image will be used on Windows Phone.
Optional urlstringA URL to share

Returns: Promise<any>


shareVia#

shareVia(appName: string, message: string, subject?: string, image?: string, url?: string): Promise<any>

Share via AppName

Parameters:

NameTypeDescription
appNamestringApp name or package name. Examples: instagram or com.apple.social.facebook
messagestring-
Optional subjectstring-
Optional imagestring-
Optional urlstring-

Returns: Promise<any>


shareViaEmail#

shareViaEmail(message: string, subject: string, to: string[], cc?: string[], bcc?: string[], files?: string | string[]): Promise<any>

Share via Email

Parameters:

NameTypeDescription
messagestring-
subjectstring-
tostring[]-
Optional ccstring[]Optional
Optional bccstring[]Optional
Optional filesstring | string[]Optional URL or local path to file(s) to attach

Returns: Promise<any>


shareViaFacebook#

shareViaFacebook(message: string, image?: string, url?: string): Promise<any>

Shares directly to Facebook

Parameters:

NameTypeDescription
messagestring-
Optional imagestring-
Optional urlstring-

Returns: Promise<any>


shareViaFacebookWithPasteMessageHint#

shareViaFacebookWithPasteMessageHint(message: string, image?: string, url?: string, pasteMessageHint?: string): Promise<any>

Shares directly to Facebook with a paste message hint

Parameters:

NameTypeDescription
messagestring-
Optional imagestring-
Optional urlstring-
Optional pasteMessageHintstring-

Returns: Promise<any>


shareViaInstagram#

shareViaInstagram(message: string, image: string): Promise<any>

Shares directly to Instagram

Parameters:

NameTypeDescription
messagestring-
imagestring-

Returns: Promise<any>


shareViaSMS#

shareViaSMS(messge: string, phoneNumber: string): Promise<any>

Share via SMS

Parameters:

NameTypeDescription
messgestringmessage to send
phoneNumberstringNumber or multiple numbers seperated by commas

Returns: Promise<any>


shareViaTwitter#

shareViaTwitter(message: string, image?: string, url?: string): Promise<any>

Shares directly to Twitter

Parameters:

NameTypeDescription
messagestring-
Optional imagestring-
Optional urlstring-

Returns: Promise<any>


shareViaWhatsApp#

shareViaWhatsApp(message: string, image?: string, url?: string): Promise<any>

Shares directly to WhatsApp

Parameters:

NameTypeDescription
messagestring-
Optional imagestring-
Optional urlstring-

Returns: Promise<any>


shareViaWhatsAppToReceiver#

shareViaWhatsAppToReceiver(receiver: string, message: string, image?: string, url?: string): Promise<any>

Shares directly to a WhatsApp Contact

Parameters:

NameTypeDescription
receiverstringPass phone number on Android, and Addressbook ID (abid) on iOS
messagestringMessage to send
Optional imagestringImage to send (does not work on iOS
Optional urlstringLink to send

Returns: Promise<any>


shareWithOptions#

shareWithOptions(options: object): Promise<any>

Shares using the share sheet with additional options and returns a result object or an error message (requires plugin version 5.1.0+)

Parameters:

options: object

The options object with the message, subject, files, url and chooserTitle properties.

NameType
Optional chooserTitlestring
Optional filesstring | string[]
Optional messagestring
Optional subjectstring
Optional urlstring

Returns: Promise<any>