MobiWeb Help

Sharing (iOS)

Bridge for opening iOS's native share sheet (UIActivityViewController) from website JavaScript with support for text, URL, and file payloads.

Bridge object: AppleShare (injected shim)

Method

Return

Description

AppleShare.canShare(payload)

Promise<boolean>

Returns whether share is available (always true on iOS if bridge is loaded)

AppleShare.share(payload)

Promise<void>

Opens native share sheet; resolves on successful share, rejects on error or cancellation

Auto Shim for navigator.share

On iOS, MobiWeb auto-injects a shim that defines:

  • navigator.share(...) (if missing)

  • navigator.canShare(...) (if missing)

This lets websites that already use the Web Share API trigger the native iOS share sheet without website changes.

Payload Shape

{ "title": "Receipt", "text": "Order #1234", "url": "https://example.com/orders/1234", "files": [ { "name": "receipt.pdf", "type": "application/pdf", "data": "<base64-encoded file data>" } ] }

Notes:

  • All fields are optional, but at least one must be provided.

  • text and url are both included in the activity view controller if provided.

  • files[].data must be base64-encoded (data URL prefix is not supported).

  • Files are written to the temporary directory and automatically cleaned up after sharing completes.

  • Maximum recommended file count: 10 files per share operation.

Examples

Using navigator.share (recommended):

// Share text and URL await navigator.share({ title: 'Order Receipt', text: 'Check out my order', url: 'https://example.com/orders/1234' }); // Share with file const response = await fetch('/invoice.pdf'); const blob = await response.blob(); await navigator.share({ title: 'Invoice', text: 'My invoice', files: [new File([blob], 'invoice.pdf', { type: 'application/pdf' })] });

Using direct bridge call:

AppleShare.share({ title: 'Hello', text: 'Shared from MobiWeb', url: 'https://example.com' }) .then(() => console.log('Share successful')) .catch((err) => console.error('Share failed:', err.message));

Platform Limitations

WKWebView on iOS does not support:

  • Direct file system access from JavaScript

  • Automatic file MIME type resolution from names alone

Solution: MobiWeb handles these transparently:

  • Files must be provided as Blob objects with proper type set

  • Temporary files are created server-side with MIME type validation

  • Cleanup happens automatically after the share completes

Result Events

The share() method returns a Promise:

  • Resolves when user completes the share action (success)

  • Rejects with an error if:

    • User cancels the share sheet

    • No share targets are available

    • File encoding fails

Cross-Platform Sharing Helper

async function shareContent(title, text, url, files = []) { try { if (typeof navigator.share !== 'undefined') { // Use native Web Share API (works on Android and iOS) await navigator.share({ title, text, url, files }); } else { console.error('Sharing not supported on this device'); } } catch (err) { if (err.name !== 'AbortError') { console.error('Share failed:', err.message); } } } // Usage shareContent( 'My Order', 'Check this out', 'https://example.com/orders/123' );
04 May 2026