Search by

firstlightui / share-receiver

wojt-janowski

Receive files, photos, links and text that people share to your NativePHP Mobile app from the iOS and Android share sheet.

Package info

github.com/firstlightui/share-receiver

Type:nativephp-plugin

pkg:composer/firstlightui/share-receiver

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0-beta1 2026-12-01 00:26 UTC

This package is auto-updated.

Last update: 2026-12-01 00:43:12 UTC


README

Share Receiver puts your NativePHP Mobile app in the iOS and Android share sheet, so people can send it photos, files, links and text from other apps.

  • iOS: a share extension, added to the Xcode project at build time, copies what was shared into an App Group folder the app reads.
  • Android: an invisible activity copies the shared files into the app's own storage. It works whether or not the app is running.
  • One share, one batch: everything shared in one go arrives as one Share, with its items in the order the share sheet gave them.
  • The app decides when files go: a share stays on the phone until your app calls ShareReceiver::delete(), so an upload, a dismissed prompt or an app restart never loses or deletes files still in use.

Free and MIT licensed. Composer package firstlightui/share-receiver, PHP namespace FirstlightUI\ShareReceiver, Kotlin package dev.firstlightui.plugins.share_receiver. Requires PHP 8.4 or later, nativephp/mobile ^4.9, Android 8 (API 26) or later and iOS 18 or later.

What this does not do

  • Upload anything. What to do with a share is your app's business: upload it, attach it to a record, or show it. Delete it when you are done.
  • Show a compose screen on iOS. The extension copies the share and closes. Your app shows whatever prompt it needs the next time it is in front.
  • Open the app on iOS without a URL scheme. open needs nativephp.deeplink_scheme on iOS. Apple discourages share extensions opening their app, so leave open off unless you need it.

Install

composer require firstlightui/share-receiver
php artisan native:plugin:register firstlightui/share-receiver
php artisan vendor:publish --tag=share-receiver-config

There is nothing to add to Info.plist or AndroidManifest.xml yourself: the plugin's build hook writes the share activity, the iOS extension target, its Info.plist and the App Group entitlements on every native:run and native:build.

iOS signing

The extension is an app of its own inside yours, with the bundle ID <app id>.share, and both share the App Group group.<app id>.

  • Simulators and development builds sign automatically; nothing to do.
  • Release builds need, in the Apple Developer portal: the App Group group.<app id>; the App Group capability on your app's identifier with that group; a second identifier <app id>.share with the same group; and an App Store provisioning profile for it. Regenerate your app's profile after adding the capability. Set the extension's profile name in SHARE_RECEIVER_IOS_PROVISIONING_PROFILE.
  • Bifrost signs the app's own bundle ID. Until it can sign extensions, add the extension's identifier and profile as above and check the first TestFlight build installs.

Configure

// config/share-receiver.php
'accept' => [
    'files' => ['image/*', 'application/pdf'], // MIME types; ['*/*'] for any file
    'urls' => true,                            // web links, such as from Safari
    'text' => false,                           // plain text, such as from Notes
],
'max_items' => 20,
'open' => '/inbox',                            // or null to stay in the sending app

These are compiled into the app, so a change takes effect on the next build.

Receive shares

A share lands in the inbox complete, or not at all. ShareReceived tells the live screen and Laravel's listeners about each new share, once per launch: straight away when the app is running, and otherwise when the first screen mounts or the app comes back to the front.

use FirstlightUI\ShareReceiver\Events\ShareReceived;
use FirstlightUI\ShareReceiver\Facades\ShareReceiver;
use Native\Mobile\Attributes\On;

public function mount(): void
{
    // A share may have arrived while another screen was showing.
    $this->shares = ShareReceiver::pending();
}

#[On(ShareReceived::class)]
public function received(string $shareId, int $itemCount): void
{
    $this->shares = ShareReceiver::pending();
}

Each Share has an id, receivedAt, and items in share order. Each SharedItem is one of:

kind Fields
SharedItemKind::File path (in the inbox), name (the original name), mimeType, size. Photos and videos are files; isImage() tells them apart.
SharedItemKind::Url url, and title when the sending app gave one.
SharedItemKind::Text text.

$share->files(), urls() and texts() filter the items, keeping their order. skipped counts items the share sheet sent that the app doesn't accept or couldn't read.

Claim, then delete

$share = ShareReceiver::claim($shareId);   // out of pending(); files stay

UploadDocuments::dispatch($share->id, array_map(fn ($f) => $f->path, $share->files()));

// In the job, once the upload succeeded:
ShareReceiver::delete($shareId);           // removes the share and its files

// Or, when it failed for good, offer it again:
ShareReceiver::release($shareId);

claim() only takes a share out of pending(), so a second screen or the next launch doesn't offer it twice. Hiding a prompt, leaving the screen or quitting the app never deletes files. Only delete() does. ShareReceiver::all() lists claimed shares too, such as ones an interrupted upload left behind.

Privacy

Shared files stay in the app's private storage, or the App Group container on iOS, until your app deletes them. Delete shares the person dismisses.

Development

composer test && composer lint && composer analyse
resources/android/gradlew -p resources/android compileHostCheckKotlin   # needs ANDROID_HOME with platform 36
bin/typecheck-ios                                                       # needs Xcode