# @rediska1114/capacitor-sharing

> Sharing plugin for Capacitor

Latest version **1.0.0** (published 2024-08-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rediska1114/capacitor-sharing
pnpm add @rediska1114/capacitor-sharing
yarn add @rediska1114/capacitor-sharing
bun add @rediska1114/capacitor-sharing
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-08-20 |
| First published | 2023-01-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 54.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | rediska1114 |
| Maintainers | rediska1114 |
| Keywords | capacitor, plugin, native |

## Links

- npm: https://www.npmjs.com/package/@rediska1114/capacitor-sharing
- Repository: https://github.com/rediska1114/capacitor-sharing
- Homepage: https://github.com/rediska1114/capacitor-sharing#readme
- Issues: https://github.com/rediska1114/capacitor-sharing/issues
- npm.io page: https://npm.io/package/@rediska1114/capacitor-sharing

## Recent versions

- 1.0.0 (latest) — 2024-08-20
- 0.0.2 — 2024-03-02
- 0.0.1 — 2023-01-16

## README

# @rediska1114/capacitor-sharing

Sharing plugin for capacitor

## Install

```bash
npm install @rediska1114/capacitor-sharing
npx cap sync
```

# Available methods:

- share(options: ShareOptions): Promise<NativeShareResult>;
- shareTo(options: ShareToOptions): Promise<boolean>;
- canShareTo(options: CanShareToOptions): Promise<boolean>;

# Usage example:

1. In your module (e.g. `app.module.ts`)

```ts
...
import { Sharing } from '@rediska1114/capacitor-sharing';

@NgModule({
	...
	providers: [
		...
		Sharing,
	],
})
export class AppModule {}

```

2. In your component or service (e.g. `sharing.service.ts`)

```ts
import { Injectable } from '@angular/core';
import { Sharing } from '@rediska1114/capacitor-sharing';

@Injectable()
export class SharingService {
  constructor(private sharing: Sharing) {}
  private facebookAppId = '123456789'; // your facebook app id

  async shareToInstagramStories() {
    const targets = await this.getAvailableSharingTargets();

    // instagram stories for example
    if (targets.instagramStories) {
      // example image in base64 format
      const stickerImageBase64 = await this.getBase64FromUrl(
        'https://www.example.com/sticker.png',
      );
      // example image in base64 format
      const backgroundImageBase64 = await this.getBase64FromUrl(
        'https://www.example.com/background.png',
      );

      this.sharing.shareTo({
        shareTo: 'instagramStories',
        facebookAppId: this.facebookAppId,
        backgroundTopColor: '#ff0000',
        backgroundBottomColor: '#00ff00',
        stickerImageBase64,
        backgroundImageBase64,
      });
    }
  }

  async getAvailableSharingTargets() {
    // check of all available sharing targets
    const [native, facebookStories, instagramStories] = await Promise.all([
      this.sharing.canShareTo({ shareTo: 'native' }),
      this.sharing.canShareTo({
        shareTo: 'facebookStories',
        facebookAppId: this.facebookAppId,
      }),
      this.sharing.canShareTo({
        shareTo: 'instagramStories',
        facebookAppId: this.facebookAppId,
      }),
    ]);

    return {
      native,
      facebookStories,
      instagramStories,
    };
  }

  async nativeShare() {
    this.sharing.share({
      title: 'Title',
      text: 'Text',
      url: 'https://www.example.com',
    });
  }

  private async getBase64FromUrl(url: string): Promise<string> {
    const response = await fetch(url);
    const blob = await response.blob();
    const reader = new FileReader();
    reader.readAsDataURL(blob);
    return new Promise((resolve, reject) => {
      reader.onloadend = () => {
        resolve(reader.result as string);
      };
    });
  }
}
```

# Changes in 1.x.x

- added android support
- added support for sharing to Facebook Stories
- added `shareTo()` method instead of deprecated `shareToInstagramStories()`
- added `canShareTo()` method instead of deprecated `canShareToInstagramStories()`
- share() now returns status and target of the sharing action
- updated to capacitor 5
- ios deployment_target set to 13.0 for compatibility with capacitor 5 (BREAKING CHANGE)

---
_Source: https://npm.io/package/@rediska1114/capacitor-sharing · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
