Skip to content

Commit 673125e

Browse files
committed
Update mobile 2.x documentation with API details and improvements
- Add comprehensive Camera API documentation with examples - Expand System API with battery, device info, and network status methods - Add new API documentation for Audio, File, Network, and Share - Document QR code scanning functionality - Add Icons edge component documentation - Add packaging guide for distribution - Improve permission descriptions for camera, microphone, QR code, and network state - Update CI/CD documentation with deployment examples - Enhance assets documentation with usage examples - Refine native functions documentation - Update device dropdown to display correct platform names
1 parent 6da5c5d commit 673125e

File tree

22 files changed

+1510
-47
lines changed

22 files changed

+1510
-47
lines changed

resources/views/components/navbar/device-dropdowns.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
id="mobile-dropdown"
77
>
88
<x-navbar.device-dropdown-item
9-
href="/docs/mobile/1/getting-started/introduction"
9+
href="/docs/mobile/2/getting-started/introduction"
1010
title="Documentation"
1111
subtitle="Get started with Mobile"
1212
icon="docs"

resources/views/docs/mobile/1/apis/system.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ order: 800
55

66
## Overview
77

8-
The System API provides access to basic system functions like flashlight control.
8+
The System API provides access to basic system functions like flashlight control, platform detection, and network status monitoring.
99

1010
```php
1111
use Native\Mobile\Facades\System;
@@ -34,3 +34,54 @@ Determines if the current device is running iOS.
3434
Determines if the current device is running Android.
3535

3636
**Returns:** `true` if Android, `false` otherwise
37+
38+
### `getNetworkStatus()`
39+
40+
Gets the current network connection status and details.
41+
42+
**Returns:** `?object` containing network information, or `null` if unavailable
43+
44+
```php
45+
$status = System::getNetworkStatus();
46+
47+
if ($status) {
48+
// Check if connected
49+
if ($status->connected) {
50+
echo "Connected via: " . $status->type; // "wifi", "cellular", "ethernet", or "unknown"
51+
52+
// Check if using expensive/metered connection
53+
if ($status->isExpensive) {
54+
echo "Using cellular data - consider limiting usage";
55+
}
56+
57+
// Check if Low Data Mode is enabled (iOS only)
58+
if ($status->isConstrained) {
59+
echo "Low Data Mode is enabled";
60+
}
61+
} else {
62+
echo "No network connection";
63+
}
64+
}
65+
```
66+
67+
**Response Object Properties:**
68+
69+
- `connected` (bool) - Whether the device has network connectivity
70+
- `type` (string) - Connection type: `"wifi"`, `"cellular"`, `"ethernet"`, or `"unknown"`
71+
- `isExpensive` (bool) - Whether the connection is metered/cellular
72+
- `isConstrained` (bool) - Whether Low Data Mode is enabled (iOS only, always `false` on Android)
73+
74+
**Configuration:**
75+
76+
Network state detection is enabled by default. You can disable it in `config/nativephp.php`:
77+
78+
```php
79+
'permissions' => [
80+
'network_state' => true, // Set to false to disable
81+
],
82+
```
83+
84+
**Platform Notes:**
85+
86+
- **iOS:** Uses `NWPathMonitor` from the Network framework. No additional permissions required.
87+
- **Android:** Requires `ACCESS_NETWORK_STATE` permission (automatically added when enabled)
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
---
2+
title: Audio
3+
order: 50
4+
---
5+
6+
## Overview
7+
8+
The Audio API provides access to the device's microphone for recording audio. It offers a fluent interface for starting and managing recordings, tracking them with unique identifiers, and responding to completion events.
9+
10+
```php
11+
use Native\Mobile\Facades\Audio;
12+
```
13+
14+
## Methods
15+
16+
### `record()`
17+
18+
Start an audio recording. Returns a `PendingAudioRecorder` instance that controls the recording lifecycle.
19+
20+
```php
21+
Audio::record()->start();
22+
```
23+
24+
### `stop()`
25+
26+
Stop the current audio recording. This dispatches the `AudioRecorded` event with the recording file path.
27+
28+
```php
29+
Audio::stop();
30+
```
31+
32+
### `pause()`
33+
34+
Pause the current audio recording without ending it.
35+
36+
```php
37+
Audio::pause();
38+
```
39+
40+
### `resume()`
41+
42+
Resume a paused audio recording.
43+
44+
```php
45+
Audio::resume();
46+
```
47+
48+
### `getStatus()`
49+
50+
Get the current recording status.
51+
52+
**Returns:** `string` - One of: `"idle"`, `"recording"`, or `"paused"`
53+
54+
```php
55+
$status = Audio::getStatus();
56+
57+
if ($status === 'recording') {
58+
// A recording is in progress
59+
}
60+
```
61+
62+
### `getRecording()`
63+
64+
Get the file path to the last recorded audio file.
65+
66+
**Returns:** `string|null` - Path to the last recording, or `null` if none exists
67+
68+
```php
69+
$path = Audio::getRecording();
70+
71+
if ($path) {
72+
// Process the recording file
73+
}
74+
```
75+
76+
## PendingAudioRecorder
77+
78+
The `PendingAudioRecorder` provides a fluent interface for configuring and starting audio recordings. Most methods return `$this` for method chaining.
79+
80+
### `id(string $id)`
81+
82+
Set a unique identifier for this recording. This ID will be included in the `AudioRecorded` event, allowing you to correlate recordings with completion events.
83+
84+
```php
85+
$recorderId = 'message-recording-' . $this->id;
86+
87+
Audio::record()
88+
->id($recorderId)
89+
->start();
90+
```
91+
92+
### `getId()`
93+
94+
Get the recorder's unique identifier. If no ID was set, one is automatically generated (UUID v4).
95+
96+
```php
97+
$recorder = Audio::record()
98+
->id('my-recording');
99+
100+
$id = $recorder->getId(); // 'my-recording'
101+
```
102+
103+
### `event(string $eventClass)`
104+
105+
Set a custom event class to dispatch when recording completes. By default, `AudioRecorded` is used.
106+
107+
**Throws:** `InvalidArgumentException` if the event class does not exist
108+
109+
```php
110+
use App\Events\VoiceMessageRecorded;
111+
112+
Audio::record()
113+
->event(VoiceMessageRecorded::class)
114+
->start();
115+
```
116+
117+
### `remember()`
118+
119+
Store the recorder's ID in the session for later retrieval. This is useful when the recording completes on the next request.
120+
121+
```php
122+
Audio::record()
123+
->id('voice-note')
124+
->remember()
125+
->start();
126+
```
127+
128+
### `lastId()`
129+
130+
Retrieve the last remembered audio recorder ID from the session. Use this in event listeners to correlate recordings.
131+
132+
```php
133+
use Livewire\Attributes\On;
134+
use Native\Mobile\Events\Audio\AudioRecorded;
135+
136+
#[On('native:'.AudioRecorded::class)]
137+
public function handleAudioRecorded(string $path, string $mimeType, ?string $id)
138+
{
139+
// For comparing with remembered IDs
140+
if ($id === Audio::record()->lastId()) {
141+
$this->saveRecording($path);
142+
}
143+
}
144+
```
145+
146+
### `start()`
147+
148+
Explicitly start the audio recording. This is optional - recordings auto-start if you don't call this method.
149+
150+
**Returns:** `bool` - `true` if recording started successfully, `false` if it failed or was already started
151+
152+
```php
153+
$recorder = Audio::record()->id('my-recording');
154+
155+
if ($recorder->start()) {
156+
// Recording started
157+
} else {
158+
// Recording failed - likely due to permission denial
159+
}
160+
```
161+
162+
## Events
163+
164+
### `AudioRecorded`
165+
166+
Dispatched when an audio recording completes. The event includes the file path and recording ID.
167+
168+
**Payload:**
169+
- `string $path` - File path to the recorded audio
170+
- `string $mimeType` - MIME type of the audio (default: `'audio/m4a'`)
171+
- `?string $id` - The recorder's ID, if one was set
172+
173+
```php
174+
use Livewire\Attributes\On;
175+
use Native\Mobile\Events\Audio\AudioRecorded;
176+
177+
#[On('native:'.AudioRecorded::class)]
178+
public function handleAudioRecorded(string $path, string $mimeType, ?string $id)
179+
{
180+
// Store or process the recording
181+
$this->recordings[] = [
182+
'path' => $path,
183+
'mimeType' => $mimeType,
184+
'id' => $id,
185+
];
186+
}
187+
```
188+
189+
## Notes
190+
191+
- **Microphone Permission:** The first time your app requests microphone access, users will be prompted for permission. If denied, recording functions will fail silently.
192+
193+
- **File Format:** Recordings are stored as M4A/AAC audio files (`.m4a`). This format is optimized for small file sizes while maintaining quality.
194+
195+
- **Storage Location:**
196+
- **Android:** Recordings are stored in the app's cache directory (`context.cacheDir/audio_{timestamp}.m4a`). These are temporary files and may be deleted by the system.
197+
- **iOS:** Recordings are stored persistently in `~/Library/Application Support/Audio/NativePHP_{timestamp}.m4a` and are excluded from iCloud backup.
198+
199+
- **Recording State:** Only one recording can be active at a time. Calling `start()` while a recording is in progress will return `false`.
200+
201+
- **Auto-Start Behavior:** If you don't explicitly call `start()`, the recording will automatically start when the `PendingAudioRecorder` is destroyed. This maintains backward compatibility with earlier versions.

0 commit comments

Comments
 (0)