Skip to content

Commit 23fc2a2

Browse files
V1 docs (#111)
Co-authored-by: Simon Hamp <[email protected]>
1 parent 9ff7e7e commit 23fc2a2

19 files changed

+545
-240
lines changed

resources/views/components/alert-v1-announcement.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class="hidden size-5 shrink-0 dark:block"
3333
</div>
3434

3535
{{-- Title --}}
36-
<h2 class="font-medium">NativePHP for desktop has finally reached v1!</h2>
36+
<h2 class="font-medium">NativePHP for desktop and mobile have reached v1!</h2>
3737

3838
{{-- Dot 1 --}}
3939
<div

resources/views/docs/mobile/1/digging-deeper/broadcasting.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

resources/views/docs/mobile/1/digging-deeper/databases.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ title: Databases
33
order: 200
44
---
55

6-
# Working with Databases
6+
## Working with Databases
77

88
You'll almost certainly want your application to persist structured data. For this, NativePHP supports
99
[SQLite](https://sqlite.org/), which works on both iOS and Android devices.
1010

1111
You can interact with SQLite from PHP in whichever way you're used to.
1212

13-
### Configuration
13+
## Configuration
1414

1515
You do not need to do anything special to configure your application to use SQLite. NativePHP will automatically:
1616
- Switch to using SQLite when building your application.

resources/views/docs/mobile/1/digging-deeper/files.md

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Push Notifications
3+
order: 400
4+
---
5+
6+
7+
## Overview
8+
9+
NativePHP for Mobile uses [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) to send push notifications to your users.
10+
11+
## Setting up your app
12+
13+
Once you create a Firebase account and create a project you will be offered to download a `google-services.json` file.
14+
15+
This file contains the configuration for your app and is used by the Firebase SDK to retrieve tokens for each device using your app.
16+
17+
Simply drag this file into the root of your Laravel project, enable `push_notifications` in the [config](/docs/mobile/1/getting-started/configuration) it will be used automatically.
18+
19+
You will see more instructions on how to configure your app in the Firebase documentation, you can ignore all of those, NativePHP handles all of that for you.
20+
21+
## Receiving Push Tokens
22+
23+
To receive push notifications, you must register a listener for the event. For example,
24+
take a look at how easy it is to listen for a `TokenGenerated` event in Livewire:
25+
26+
```php
27+
use Livewire\Attributes\On;
28+
use Livewire\Component;
29+
use Native\Mobile\Facades\System;
30+
use Native\Mobile\Events\PushNotification\TokenGenerated;
31+
32+
class PushNotifications extends Component
33+
{
34+
public function render()
35+
{
36+
return view('livewire.system.push-notifications');
37+
}
38+
39+
#[On('native:' . TokenGenerated::class)]
40+
public function handlePushNotifications(string $token)
41+
{
42+
// Do something with the token...
43+
}
44+
}
45+
```
46+
47+
Because of the nature of mobile applications you need an api server to handle these tokens. You can use Laravel's built-in `Http` facade to
48+
`POST` the token to your server, on the server side you need to associate the token with the "user" that owns the device.
49+
50+
We **strongly** recommend using [Sanctum](https://laravel.com/docs/12.x/sanctum#main-content) to handle this for you.
51+
52+
## The flow
53+
54+
Your app authenticates users against your own api server, when users create an account or login the server validates and authenticates the user and passes back a Sanctum token.
55+
56+
The token is stored in your apps `session` and is used on subsequent requests to the api server.
57+
58+
When a push notification is received, the token is sent to your api server and the server stores it for the user who sent it.
59+
60+
> Optionally, you can have a `HasMany` relationship between your users and devices,
61+
> this allows you to associate a device with a user and then use the device's token
62+
> to send push notifications to that users devices.
63+
64+
## Sending Push Notifications
65+
66+
Once you have the token, you may use it from your server-based applications to trigger Push Notifications directly to
67+
your user's device. We use a package like [google/apiclient](https://github.com/googleapis/google-api-php-client) to send the notifications.
68+
69+
This is the exact code used by the NativePHP Kitchen Sink App (available soon on all app stores and GitHub):
70+
71+
```php
72+
Route::group(['middleware' => 'auth:sanctum'], function () {
73+
Route::post('send-push-notification', PushNotificationController::class)->name('send-push-notification');
74+
});
75+
```
76+
77+
```php
78+
namespace App\Http\Controllers;
79+
80+
use App\Jobs\SendPushNotification;
81+
use Illuminate\Http\Request;
82+
83+
class PushNotificationController extends Controller
84+
{
85+
public function __invoke(Request $request)
86+
{
87+
$token = $request->get('token');
88+
89+
$request->user()->update([
90+
'push_token' => $token
91+
]);
92+
93+
SendPushNotification::dispatch($token)->delay(now()->addMinutes(1));
94+
}
95+
}
96+
```

resources/views/docs/mobile/1/getting-started/configuration.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,50 @@ title: Configuration
33
order: 200
44
---
55

6-
# COMING SOON
6+
## Overview
7+
8+
NativePHP for Mobile is designed so that most configuration happens **inside your Laravel application**, without requiring you to manually open Xcode or Android Studio.
9+
10+
After installation, NativePHP sets up the necessary native scaffolding, but your primary interaction remains inside Laravel itself.
11+
12+
This page explains the key configuration points you can control directly through Laravel.
13+
14+
## The `nativephp.php` Config File
15+
16+
The nativephp.php config file is where you can configure the native project for your application.
17+
18+
NativePHP uses sensible defaults and makes several assumptions based on default installations for tools required to build and run apps from your computer.
19+
20+
You can override these defaults by editing the `nativephp.php` config file in your Laravel project or changing environment variables.
21+
22+
```dotenv
23+
NATIVEPHP_APP_VERSION
24+
NATIVEPHP_APP_VERSION_CODE
25+
NATIVEPHP_APP_ID
26+
NATIVEPHP_DEEPLINK_SCHEME
27+
NATIVEPHP_DEEPLINK_HOST
28+
NATIVEPHP_APP_AUTHOR
29+
NATIVEPHP_GRADLE_PATH
30+
NATIVEPHP_ANDROID_SDK_LOCATION
31+
```
32+
33+
## Cleanup `env` keys
34+
35+
The `cleanup_env_keys` array in the config file allows you to specify keys that should be removed from the `.env` file before bundling.
36+
This is useful for removing sensitive information like API keys or other secrets.
37+
38+
## Cleanup `exclude_files`
39+
40+
The `cleanup_exclude_files` array in the config file allows you to specify files and folders that should be removed before bundling.
41+
This is useful for removing files like logs or other temporary files.
42+
43+
## Permissions
44+
In general, the app stores don't want apps to request permissions that they don't need.
45+
To enable some permissions your app needs you simply need to change their values in the permissions section.
46+
47+
```dotenv
48+
biometric
49+
camera
50+
nfc
51+
push_notifications
52+
```

resources/views/docs/mobile/1/getting-started/debugging.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

resources/views/docs/mobile/1/getting-started/development.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,30 @@ title: Development
33
order: 300
44
---
55

6-
# COMING SOON
6+
7+
## The `nativephp` Directory
8+
9+
After running: `php artisan native:install` you’ll see a new `nativephp` directory at the root of your Laravel project as well as a `nativephp.php` config file in your config folder in the Laravel root.
10+
11+
This folder contains all the native project files that NativePHP generates for you.
12+
13+
You should not need to manually open or edit any native project files under normal circumstances.
14+
NativePHP handles the heavy lifting for you.
15+
16+
## NATIVEPHP_APP_VERSION
17+
18+
The NATIVEPHP_APP_VERSION environment variable controls your app's versioning behavior.
19+
20+
When building for Android, NativePHP first copies the relevant Laravel files into a temporary directory, zips them, and embeds the archive into the Android project. When the app boots, it checks the embedded version against the previously installed version.
21+
22+
If the versions match, the app uses the existing files without re-extracting the archive.
23+
24+
If the versions differ — or if the version is set to ***DEBUG*** — the app updates itself by re-extracting the new bundle.
25+
26+
This mechanism ensures developers can iterate quickly during development, while providing a faster, more stable experience for end users once an app is published.
27+
28+
> Rule of Thumb:
29+
> During development, keep NATIVEPHP_APP_VERSION set to DEBUG to always refresh the app.
30+
> When preparing a new release, update it to a semantic version (e.g., 1.2.3) to enable versioned updates for your users.
31+
732

resources/views/docs/mobile/1/getting-started/env-files.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

resources/views/docs/mobile/1/getting-started/installation.md

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,58 @@ order: 100
55

66
## Requirements
77

8-
Right now, NativePHP for mobile only supports building iOS applications. Android is in the works already and coming soon!
9-
10-
Apple's tooling for building iOS apps requires that you compile your applications using macOS.
11-
128
1. PHP 8.3+
139
2. Laravel 10 or higher
1410
3. An Apple Silicon Mac running macOS 12+ with Xcode 16+
1511
4. An active [Apple Developer account](https://developer.apple.com/)
16-
5. [A NativePHP for mobile license](https://checkout.anystack.sh/nativephp)
12+
5. [A NativePHP for mobile license](https://checkout.anystack.sh/nativephp)
1713
6. _Optional_ iOS device
1814

19-
You don't _need_ a physical iOS device to compile your application and test it for iOS, as NativePHP for mobile supports
20-
the iOS Simulator. However, we highly recommend that you test your application on a real device before submitting to the
21-
App Store.
2215

23-
You can download Xcode from the Mac App Store.
16+
#### For iOS
17+
1. An Apple Mac (ideally Silicon) running macOS 12+ with Xcode 16+
18+
2. An active [Apple Developer account](https://developer.apple.com/)
19+
3. You can download Xcode from the Mac App Store
2420

25-
The most painless way to get PHP and Node up and running on your system is with
26-
[Laravel Herd](https://herd.laravel.com). It's fast and free!
21+
#### For Android
22+
1. [Android Studio Giraffe (or later)](https://developer.android.com/studio)
23+
2. The following environment variables set.
24+
3. You should be able to successfully run `java -v` and `adb devices` from the terminal.
25+
4. **Windows only**: You must have [7zip](https://www.7-zip.org/) installed.
26+
27+
#### For macOS
28+
```shell
29+
export JAVA_HOME=$(/usr/libexec/java_home -v 17) // This isn't required if JAVA_HOME is already set in the Windows Env Variables
30+
export ANDROID_SDK_ROOT=$HOME/Library/Android/sdk
31+
export PATH=$PATH:$JAVA_HOME/bin:$ANDROID_HOME/emulator:$ANDROID_HOME/tools:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools
32+
```
2733
28-
### Laravel
34+
#### For Windows
35+
```shell
36+
set ANDROID_SDK_ROOT=C:\Users\yourname\AppData\Local\Android\Sdk
37+
set PATH=%PATH%;%JAVA_HOME%\bin;%ANDROID_SDK_ROOT%\platform-tools
2938
30-
NativePHP for mobile is built to work best with Laravel. You can install it into an existing Laravel application, or
31-
[start a new one](https://laravel.com/docs/installation).
39+
# This isn't required if JAVA_HOME is already set in the Windows Env Variables
40+
set JAVA_HOME=C:\Program Files\Microsoft\jdk-17.0.8.7-hotspot
41+
```
3242
33-
## Private package
43+
> **Note** You cannot build iOS apps on Windows or Linux
44+
45+
You don't _need_ a physical iOS/Android device to compile your application and test it for your app, as NativePHP for mobile supports
46+
the iOS Simulator and Android emulators. However, we highly recommend that you test your application on a real device before submitting to the
47+
App/Google Play Store.
48+
49+
## Laravel
50+
51+
NativePHP for mobile is built to work with Laravel. You can install it into an existing Laravel application, or
52+
[start a new one](https://laravel.com/docs/installation). The most painless way to get PHP and Node up and running on your system is with
53+
[Laravel Herd](https://herd.laravel.com). It's fast and free!
54+
55+
56+
## Install NativePHP for mobile
3457
3558
To make NativePHP for mobile a reality has taken a lot of work and will continue to require even more. For this reason,
36-
it's not open source and you are not free to distribute or modify its source code.
59+
it's not open source, and you are not free to distribute or modify its source code.
3760
3861
Before you begin, you will need to purchase a license.
3962
Licenses can be obtained via [Anystack](https://checkout.anystack.sh/nativephp).
@@ -49,19 +72,24 @@ Once you have your license, you will need to add the following to your `composer
4972
],
5073
```
5174
52-
## Install NativePHP for mobile
53-
75+
Then run:
5476
```shell
55-
composer require nativephp/ios
77+
composer require nativephp/mobile
5678
```
57-
This package contains all the libraries, classes, commands, and interfaces that your application will need to work with
58-
iOS.
5979
60-
If this is the first time you're installing the package, you will be prompted to authenticate.
80+
If this is the first time you're installing the package, you will be prompted to authenticate. Your username is the
81+
email address you registered with Anystack. Your password is your license key.
6182
62-
Your username is the email address you registered with Anystack.
83+
This package contains all the libraries, classes, commands, and interfaces that your application will need to work with
84+
iOS and Android.
6385
64-
Your password is your license key.
86+
**Before** running the `install` command it is important to set the following variables in your `.env`:
87+
88+
```shell
89+
NATIVEPHP_APP_ID=com.nativephp.yourapp
90+
NATIVEPHP_APP_VERSION="DEBUG"
91+
NATIVEPHP_APP_VERSION_CODE="1"
92+
```
6593
6694
## Run the NativePHP installer
6795
@@ -70,11 +98,7 @@ php artisan native:install
7098
```
7199
72100
The NativePHP installer works similarly to NativePHP for desktop, taking care of setting up and configuring your Laravel
73-
application to work with iOS.
74-
75-
After you've run this command, you'll see a new `ios` folder in the root of your Laravel project.
76-
77-
We'll come back to this later.
101+
application to work with iOS and/or Android.
78102
79103
## Start your app
80104
@@ -87,21 +111,18 @@ Once you're ready:
87111
php artisan native:run
88112
```
89113
90-
This will start compiling your application and boot it in the iOS Simulator by default.
114+
This will start compiling your application and boot it on whichever device you select.
91115
92116
### Running on a real device
93117
94-
If you want to run your app on a real iOS device, you need to make sure the device is in
95-
[Developer Mode](https://developer.apple.com/documentation/xcode/enabling-developer-mode-on-a-device) and that it's
96-
been added to your Apple Developer account as
118+
#### For iOS
119+
If you want to run your app on a real mobile device, you need to make sure the device is in
120+
[Developer Mode](https://developer.apple.com/documentation/xcode/enabling-developer-mode-on-a-device)
121+
and that it's been added to your Apple Developer account as
97122
[a registered device](https://developer.apple.com/account/resources/devices/list).
98123
99-
Then you can simply run and choose your device from the list of available devices:
100-
101-
```shell
102-
php artisan native:run
103-
```
104-
105-
Alternatively, you may open the `ios/NativePHP.xcodeproj` file in Xcode and run builds using Xcode's UI.
124+
#### For Android
125+
On Android you need to [enable developer options](https://developer.android.com/studio/debug/dev-options#enable)
126+
and have USB debugging (ADB) enabled.
106127
107128
And that's it! You should now see your Laravel application running as a native app! 🎉

0 commit comments

Comments
 (0)