Skip to content

A mobile app

A Protobase app runs as an iOS or Android app with nothing more than a mobile section in its protobase.config.ts. protobase mobile wraps the app in Capacitor: the app’s shell, its UI plugins, theme and favicon open from files on the device, and the app calls your server’s API.

  • iOS, on a Mac: Xcode, with a simulator.
  • Android: the Android SDK, with an emulator, and JDK 21.

Set their variables, such as ANDROID_HOME and JAVA_HOME, in your shell, not in the project’s .env: the commands hand npm and Capacitor no variable named in any of the project’s .env* files, even when the shell sets a variable of the same name, since those files hold the app’s secrets.

protobase.config.ts
import { defineConfig } from '@protobase/config'
export default defineConfig({
// ...
mobile: {
appId: 'com.example.shop',
plugins: { '@capacitor/camera': '^8.0.0' },
},
})
  • appId is the app’s id in reverse-DNS form, the same on iOS and Android: at least two parts separated by dots, each starting with a letter and holding only letters and digits. Underscores and hyphens are refused, as iOS rejects underscores and Android rejects hyphens; protobase mobile stops early on such an id and suggests one without them.
  • plugins, optional, are extra native Capacitor plugins, npm name to version. Capacitor itself, @capacitor/app, @capacitor/keyboard, @capacitor/splash-screen and @capawesome/capacitor-live-update come with Protobase at fixed versions and cannot be listed. A plugin runs native code with the app’s rights, so list only plugins the app needs. A plugin’s JavaScript cannot call CapacitorHttp, CapacitorCookies or WebView, and Capacitor.convertFileSrc URLs do not load: call those from the plugin’s native code.

The app is installed under the name it shows in its upper left, on iOS and Android alike: protobase mobile reads it from the server the app calls (its web manifest), so a PROTOBASE_APP_NAME the server runs with names the app on the phone too. When that server cannot be reached, run and open warn and take the project’s own name, the config’s name or PROTOBASE_APP_NAME in its environment, and build stops.

On the home screen the app shows its own icon, or Protobase’s without one, on iOS and Android alike. While it starts, its splash screen shows that icon in the middle of the app’s background, unless you set one of its own: the --background token of its protobase.theme.css, or the default without one, light or dark as the phone is. protobase mobile takes it as a colour such as #f4f3ee, rgb(), hsl() or white, and stops on one a phone’s splash screen cannot show, such as oklch() or var().

With a mobile section, the API answers the app’s origins, capacitor://localhost on iOS and https://localhost on Android, through CORS. Apps without one get no new dependency, and protobase build and protobase dev work as before.

Signing in works in the app as on the web, with nothing more to set up:

  • Emailed codes, passwords and the second step of two-factor authentication work. Passkeys do not work in the app yet. Sign-in with another provider does not work in the app yet.
  • The app calls /api/auth through the device’s native HTTP, naming its Capacitor origin. With a mobile section, sign-in trusts the Capacitor origin a request names, for that request only, without CORS. A POST from a Capacitor origin must send a JSON body: any other is refused with 415, as only a page in the app sends one.
  • The session survives reloads, updates and relaunches. On Android it lives in the device’s cookie store; on iOS in a keychain item that stays on the device, out of the WebView and the device’s cookie store.
  • “Forgot password?” is not offered in the app, as the emailed link cannot lead back into it.
  • Page script cannot reach the session cookie, on iOS and Android alike: Capacitor’s CapacitorHttp, CapacitorCookies and WebView plugins are refused to it, and so are the app’s local file routes. A plugin that reads files for its JavaScript, such as @capacitor/filesystem, could still hand the cookie over.
  • While you develop over plain http://localhost with a mobile section, a page served on https://localhost in the same browser can send sign-in requests that carry your dev session, as some browsers treat the two as the same site. Do not open untrusted pages on https://localhost while you develop.

Name one square image in the mobile section, and every icon size for iOS and Android is made for you: the App Store icon with iOS’s dark and tinted icons, and Android’s launcher, round, adaptive and themed icons. Without one, the app shows the Protobase icon.

mobile: { appId: 'com.example.shop', icon: 'icon.png' },
  • icon is a path from the project’s folder to a square PNG of at least 1024 × 1024 pixels, or a square SVG. protobase mobile stops on a missing file, any other format, an image that is not square or a smaller PNG, naming mobile.icon.
  • The icon sits on the app’s backgroundColor, or on the splash screen’s light background without one: iOS’s App Store icon is filled with it, as the App Store takes no transparency, and it is the background of Android’s adaptive icon. With an icon, backgroundColor must be an opaque colour such as #ffffff, rgb() or hsl().
  • Android’s adaptive icon draws the whole image within the middle 66 of its 108 dp, the safe zone no launcher’s mask cuts into.
  • An image on a transparent background also gives iOS’s dark icon, its mark on the dark background iOS draws, and its tinted icon, the mark in greyscale, and Android’s themed icon, in the mark’s shape. An image without transparency gives none of these: iOS makes its dark and tinted icons from the App Store icon, and Android shows the icon as it is. A mark on a transparent background suits every platform best.
  • The splash screen shows the app’s icon too, on iOS with its corners rounded.

Changing the icon takes a new store release: a live update does not change it.

Set a splash image and background colour in the mobile section, with dark-mode values if you like, and the app opens on that image in the middle of that colour, on iOS and Android alike. Without them it opens on its icon over its theme background.

mobile: {
appId: 'com.example.shop',
splash: { image: 'splash.png', background: '#0d9488', dark: { image: 'splash-dark.png', background: '#042f2e' } },
},
  • image is a path from the project’s folder to a square PNG of at least 1152 × 1152 pixels, or a square SVG. Android shows it at 288 dp and only its middle circle, two thirds of its side across, so keep everything you want seen within that circle; iOS shows the same circle. protobase mobile stops on a missing file, any other format, an image that is not square or a smaller PNG, naming the setting.
  • background is an opaque colour such as #0d9488, rgb() or hsl(); protobase mobile stops on any other, naming the setting.
  • dark holds the image and background for dark mode. One left out there takes the light one, so a single image and colour serve both. A dark image needs a light one.
  • Each is optional: an image without a background sits on the theme background, and a background without an image shows the icon on it.

The splash image is a centred image, not full-screen artwork, as that is all Android’s splash screen shows. Changing it takes a new store release: a live update does not change it.

Terminal window
protobase mobile run android
protobase mobile run ios

The first run installs Capacitor into .protobase/mobile/, which ignores itself in git. Every run builds the app’s files as protobase build does and generates the native project from your config again, so never edit the projects in .protobase/mobile/ by hand. Your own package.json gains nothing.

In the app, the admin keeps clear of the status bar, the notch, the home indicator and Android’s system bars, and it does not zoom: a focused input leaves the page at its scale, and so does a pinch. The status bar’s text cannot follow the theme chosen in the app, only the phone’s light or dark mode, because setting the status bar’s style is not implemented.

The app calls the server at the app’s url (PROTOBASE_URL by default); pass --api https://shop.example.com for another one. Plain http is only for a server on this machine (localhost) or, on the Android emulator, its host 10.0.2.2; any other server needs https. An Android phone on USB reaches a server on localhost through a forwarded port; an iPhone needs an https server. The app’s UI plugins load from the device only when the server serves a built bundle (protobase serve dist): against protobase dev, use --live.

--target <id> picks the simulator, emulator or device; without it Capacitor asks.

To run on your iPhone, connect it, turn on its Developer Mode and pass your Apple team id, from a paid Apple Developer membership or the free personal team of the Apple ID you added in Xcode’s settings:

Terminal window
protobase mobile run ios --team ABCDE12345

Every run signs the app for development with that team, letting Xcode create the profile and register the phone, and installs it on the connected iPhone, or on --target when several are connected. The first time, trust your developer certificate on the phone in Settings, General, VPN & Device Management. A free team signs only an appId no one else has taken.

In the iOS and Android app, Import and file fields open the phone’s file picker, offering Excel, CSV and JSON files from the device and its cloud drives, with nothing to set up. On Android, a CSV that a drive labels as another type, or as a file of no known type, can be picked too; Import reads a file by its name. On the iOS Simulator a workbook of 100,000 rows reads in about 8 seconds.

Terminal window
protobase dev
protobase mobile run android --live

With --live the app opens the running protobase dev instead of its own files, so it reloads as you save. --port names the dev server’s port, by default the one protobase dev keeps for the project.

Terminal window
protobase mobile open ios

opens the generated project in Xcode, or Android Studio for android. To run it from Xcode on an iPhone, pick a signing team in Signing & Capabilities, or use protobase mobile run ios --team.

Terminal window
protobase mobile build android --app-version 1.2.3 --build-number 7 --api https://shop.example.com
protobase mobile build ios --app-version 1.2.3 --build-number 7 --api https://shop.example.com --team ABCDE12345

makes a signed release binary: an .aab to upload to Google Play, an .ipa to upload to App Store Connect. It goes to mobile-release/, which ignores itself in git, named <appId>-<version>-<build number>; --out <dir> picks another folder.

  • The binary carries the app’s files, so it opens without a network and never downloads anything on its first launch; offline it says it cannot reach the server, as the web app does.
  • A release calls its server over https, at --api or the app’s url: plain http, localhost and 10.0.2.2 are refused.
  • --app-version is the version the stores show, one to three numbers such as 1.2.3. --build-number is a whole number that must rise with every upload, such as your CI’s run number.
  • Extra plugins run at build time with access to your signing key, so add only plugins you trust.
  • iOS and Android apps built by protobase mobile run and protobase mobile build carry nothing over to a new phone or from a backup, so no working session sits in a backup or on another phone. Android apps opt out of backup and device-to-device transfer; an iOS app keeps its session in a keychain item that never leaves the device, and its first launch after a restore, even on the same iPhone, or a move to a new one, removes everything the app kept before its page loads. On a new phone, or after restoring a backup, the app starts as a fresh install: your users sign in again, and unsent drafts and downloaded live updates are gone. Reinstalling an iOS app starts it as a fresh install too.

Android. Make an upload key once, outside the project, and never commit it:

Terminal window
keytool -genkeypair -v -keystore ~/.android-keys/upload.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload

Use it as the upload key with Play App Signing. Set these variables in your shell or as CI secrets, never as command arguments, where other users of the machine can read them:

  • PROTOBASE_ANDROID_KEYSTORE: the keystore file, absolute or relative to the project folder.
  • PROTOBASE_ANDROID_KEYSTORE_PASSWORD and PROTOBASE_ANDROID_KEY_PASSWORD: its passwords.
  • PROTOBASE_ANDROID_KEY_ALIAS: the key’s alias, upload above.

Only Gradle gets them, for the length of the build: npm, its install scripts and Capacitor never do. The build needs the Android SDK and JDK 21.

iOS, on a Mac with Xcode: --team is your Apple Developer team id, shown in your account’s membership details. Xcode signs with the certificates and profiles of the account you added in its settings. For manual signing, pass --certificate <name> and --profile <name> too. Manual signing cannot use a certificate or profile name that holds <, > or & because writing the escaped export options is not implemented. Xcode creates the certificates and profiles a new app lacks.

To sign without an account in Xcode, as on a build machine, make an App Store Connect API key with the Admin role and set PROTOBASE_IOS_API_KEY_PATH to its .p8 file, absolute or relative to the project folder, PROTOBASE_IOS_API_KEY_ID to its key id and PROTOBASE_IOS_API_KEY_ISSUER to its issuer id. Set all three or none; manual signing ignores them. The bundle id must exist on the team first.

The app updates its files itself from your server, on Android and iOS alike, so it gets UI changes without a store release. Make a key pair once:

Terminal window
protobase mobile keys

Set PROTOBASE_MOBILE_SIGNING_KEY from its first line on the server, as a secret, and put the public key in the mobile section, which is safe to commit:

mobile: {
appId: 'com.example.shop',
publicKey: `-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----`,
},

Build the binary again. Each deploy of the app then reaches it: it downloads the files that changed in the background and runs them at its next start, or when it comes back to the foreground after 5 minutes or more away, on the page it showed and still signed in, behind its splash screen. Right after someone signs in, it switches before the app opens. It never switches while in use, within 5 minutes of leaving it, or over unsaved changes on the page, and it asks nobody to reload. A release that fails to start goes back to the files the binary carries. Releases come from a server of the same Protobase minor as the binary (below 1.0) and the same native code; a newer minor, or a Protobase release that changes the native code, needs a store release. See the live updater.

A native host app that embeds the shell and serves its files in its own views, rather than through the Capacitor web view, takes the same releases through the same checks with HostedReleases from @protobase/mobile’s iOS package. The host decides when a new release takes over:

let releases = try HostedReleases.make(
HostedReleaseSettings(apiOrigin: "https://shop.example.com", publicKey: publicKey, fingerprint: fingerprint, shellVersion: shellVersion, builtInOrder: builtInOrder),
builtInFiles: Bundle.main.url(forResource: "shell", withExtension: nil)!
).get()
serve(releases.currentFiles) // the release swapped in earlier, or the binary's own files
releases.check { outcome in // downloads and checks a new release in the background
if case .ready = outcome { /* swap it in when nothing is open */ }
}
if releases.swap() { serve(releases.currentFiles) }

Each set of files a host serves takes its own name, so their releases stay apart. A swapped-in release that no longer passes its checks, or that an update of the app made older than the files it carries, gives way to the binary’s own files at the next start.

You submit the app under your own developer account, on both stores: Apple rejects apps from a template or app generation service unless the provider of the app’s content submits them (App Review Guidelines 4.2.6).

  • What may change without a store release: the app’s files, which a later Protobase release can update over the air: the shell, UI plugins, theme, in-app logo and copy, and fixes and features within the app’s purpose. Apple allows downloaded interpreted code that does not change the app’s primary purpose (Apple Developer Program License Agreement 3.3.1(B)), and Google Play allows JavaScript in a WebView (Device and Network Abuse).
  • What needs a store release: native code, Capacitor or plugin changes (mobile.plugins), turning push on or off, permissions, the app’s name, its home-screen icon and its splash screen.
  • Big new features still go through Apple’s review with a store release, even when they could ship over the air: Apple asks that an app’s features be documented and reviewed, none hidden (App Review Guidelines 2.3.1 and 2.5.19).
  • Account deletion is built in: Apple requires an app that lets people create an account to let them delete it in the app too (App Review Guidelines 5.1.1(v)). The account page’s Delete account does that, on by default; keep auth.accountDeletion on for an app you submit.
  • A plain WebView of an admin app risks rejection: Apple expects an app to be more than a repackaged website (4.2). Native touches help, such as push notifications, sharing, the camera or biometric sign-in, through mobile.plugins.

With notifications() on, protobase mobile sets push up in the app itself: there is no push setting in the mobile section.

The user turns push on from the bell, or from your own button with usePushNotifications. The phone asks for the permission then. Signing out removes the phone’s registration.

A tap on a notification whose url is on your app’s server opens that page inside the app. Any other http or https url opens in the phone’s browser, never inside the app, and any other url opens nothing. Turning push on or off changes the app’s native code, so it ships in a store release, not a live update. An app with notifications() on cannot get live updates on Protobase Cloud because fingerprinting its release with the manifest’s push is not implemented there. A self-hosted server cannot offer live updates to an app whose config function turns notifications() on for build and not for serve, or the other way round, because fingerprinting a served release from its bundle’s manifest is not implemented.

Put your Firebase project’s google-services.json in the project folder, next to protobase.config.ts. You download it from the Firebase console (Project settings, Your apps, an Android app whose package name is the mobile section’s appId). Every protobase mobile run and build copies it into the Android app. Without it, the Android app builds without push and every run says so, naming the path. The server sends through FCM once you set PROTOBASE_FCM_SERVICE_ACCOUNT. Android asks for the permission from Android 13 on.

protobase mobile adds the push capability to the iOS app and forwards its APNs token to Capacitor itself, on every run and build. Automatic signing turns push on for the app id in your Apple developer account; with manual signing (--certificate and --profile), the provisioning profile must include push notifications. A free team cannot sign an app with push, so running one on a phone needs a paid team; the simulator needs none.

The server sends through APNs once you create an APNs key in your Apple developer account (Certificates, Identifiers & Profiles, Keys) and set three variables on the server: the .p8 file’s text in PROTOBASE_APNS_KEY, with its line breaks or pasted on one line, the key’s id in PROTOBASE_APNS_KEY_ID and your team’s id in PROTOBASE_APNS_TEAM_ID. See iOS in the notifications reference.

Development runs (protobase mobile run and open) register with the APNs sandbox, and store builds (protobase mobile build) with production, so a phone gets push only from a server sending to the environment its build registered in.