Platform Integration
|
This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. |
Capacitor does not hide the native platforms; it generates them and then gets out of the way. After
npx cap add android and npx cap add ios your repository contains two ordinary native projects that you open in
Android Studio and Xcode, commit to Git, and customise. This page explains what lives where, which settings
belong in capacitor.config.ts and which belong in native files, and how to wire up the platform features that a
real app such as Trailhead (com.example.trailhead) needs. The baseline is Capacitor 8.6.0 with
Ionic Framework 9.0.10; Capacitor 8 needs Node 22+, Xcode 26.0+ and Android Studio Otter 2025.2.1+, with an iOS
deployment target of 15.0 and Android minSdk 24 (compileSdk and targetSdk 36).
It follows Architecture and the Native Bridge and Capacitor Plugins. Within the wider topic, start from Hybrid Apps.
The Native Projects
| Path | Purpose |
|---|---|
|
Angular source and the web build output (the folder named by |
|
A Gradle project opened in Android Studio; |
|
An Xcode project ( |
|
Shared configuration, copied into both native projects on every sync |
Commit android/ and ios/. They contain your manifest entries, signing setup, icons and any native code you add.
Build outputs (build/, Pods/, derived data) are ignored by the templates' own .gitignore files.
How Sync Works
npx cap sync does two jobs: it copies the web build and configuration into each native project, and it
updates the native dependencies so installed Capacitor plugins are linked. Use npx cap copy when only the web
assets changed, and npx cap sync after installing or removing a plugin.
npx ng build
npx cap sync
npx cap open android
npx cap open ios
capacitor.config.ts
import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.example.trailhead',
appName: 'Trailhead',
webDir: 'www',
server: {
androidScheme: 'https',
},
plugins: {
SplashScreen: {
launchShowDuration: 0,
},
},
};
export default config;
| Option | Meaning |
|---|---|
|
Reverse-domain identifier; becomes the Android |
|
Display name used when the native projects are generated |
|
Folder containing the built web app; must match the Angular build output directory |
|
Controls how the WebView loads content; |
|
Per-plugin configuration keyed by plugin name |
Changing appId or appName after the native projects exist does not rewrite them automatically; edit the
native files too. Run npx cap sync after any config change so the copies stay current.
Permissions
Capacitor plugins declare what they can do, but the app must declare the permissions it will ask for, and the operating system shows its prompt at first use. Trailhead needs the camera and the position.
Android
<!-- android/app/src/main/AndroidManifest.xml -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<!-- application element omitted -->
</manifest>
Each plugin’s documentation lists the exact entries it needs. Declare only what you use, because store reviewers and users read the list.
iOS
iOS refuses to start a camera or location request without a human-readable explanation in Info.plist.
<!-- ios/App/App/Info.plist -->
<key>NSCameraUsageDescription</key>
<string>Trailhead uses the camera to attach a photo to your hike.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Trailhead lets you choose an existing photo for your hike.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Trailhead records where you hiked when you log a hike.</string>
At runtime each plugin exposes checkPermissions() and requestPermissions(). Ask in context, right before the
feature, and handle denial with an explanation instead of an error.
import { Geolocation } from '@capacitor/geolocation';
const status = await Geolocation.checkPermissions();
if (status.location !== 'granted') {
await Geolocation.requestPermissions();
}
App Icons and Splash Screens
Both platforms need many icon sizes. The @capacitor/assets tool generates them from source images placed in an
assets/ folder (for example icon-only.png, icon-foreground.png, icon-background.png, splash.png and
splash-dark.png):
npm install --save-dev @capacitor/assets
npx capacitor-assets generate
Check the generated output in both native projects before committing. The runtime splash behaviour comes from
@capacitor/splash-screen 8.0.2, whose options live under plugins.SplashScreen in the config. Hide it from
your code once the first screen is ready with SplashScreen.hide().
Status Bar, Keyboard and Safe Areas
Modern phones have notches, rounded corners, gesture bars and, on Android 15 and later, enforced edge-to-edge
layout: the app draws behind the system bars. Capacitor 8 removed the old
android.adjustMarginsForEdgeToEdge option, so layout is now your responsibility, solved in two ways:
-
In CSS, use the
env()safe-area variables:env(safe-area-inset-top),env(safe-area-inset-right),env(safe-area-inset-bottom)andenv(safe-area-inset-left). -
Use the System Bars core plugin to control bar style and visibility from TypeScript.
Ionic’s own components (ion-header, ion-toolbar, ion-content, ion-tab-bar) already add safe-area padding,
so most screens need nothing extra. Custom full-screen elements do:
.map-overlay {
padding-top: env(safe-area-inset-top);
padding-bottom: env(safe-area-inset-bottom);
}
For the viewport to expose these values, the viewport meta tag in src/index.html needs viewport-fit=cover,
which the Ionic starters already include. The keyboard resize behaviour on iOS is configurable through the
Keyboard plugin options; Ionic scrolls focused inputs into view by default. The density entry must be present
in the Android configChanges attribute of the main activity in Capacitor 8, which the generated manifest
already includes. Do not remove it when editing the file.
Push Notifications
@capacitor/push-notifications registers the device with the platform service and delivers messages: Firebase
Cloud Messaging on Android, and the Apple Push Notification service (APNs) on iOS, where FCM can also relay. The
moving parts are:
-
Create the Firebase project and add
google-services.jsontoandroid/app. -
In the Apple Developer account enable the Push Notifications capability for the app id and create an APNs key.
-
Call
PushNotifications.requestPermissions(), thenPushNotifications.register(). -
Send the token from the
registrationevent to your backend, and handlepushNotificationReceived(foreground) andpushNotificationActionPerformed(tap).
import { PushNotifications } from '@capacitor/push-notifications';
export async function initPush(send: (token: string) => Promise<void>): Promise<void> {
const perm = await PushNotifications.requestPermissions();
if (perm.receive !== 'granted') {
return;
}
await PushNotifications.addListener('registration', (t) => send(t.value));
await PushNotifications.register();
}
Follow the plugin guide for the Xcode capability and the Android notification channel setup; both are manual steps in the native projects.
Deep Links, Universal Links and App Links
A deep link opens a specific screen, for example https://trailhead.example.com/trails/42. Three pieces make it
work: a verified association between domain and app, native configuration, and a listener that routes inside
Angular.
-
Android app links: an intent filter with
android:autoVerify="true"in the manifest, plus a/.well-known/assetlinks.jsonfile on the domain. -
iOS universal links: the Associated Domains capability (
applinks:trailhead.example.com) and anapple-app-site-associationfile on the domain. -
Routing: listen for
appUrlOpenand navigate.
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="trailhead.example.com" />
</intent-filter>
import { NgZone, inject } from '@angular/core';
import { Router } from '@angular/router';
import { App } from '@capacitor/app';
export function listenForDeepLinks(): void {
const router = inject(Router);
const zone = inject(NgZone);
App.addListener('appUrlOpen', ({ url }) => {
const path = new URL(url).pathname;
zone.run(() => router.navigateByUrl(path));
});
}
Routing details are in Navigation and Routing.
Background Work
Web timers are throttled or suspended when the app is backgrounded. For genuine background work (periodic sync, long uploads) use native facilities exposed through plugins, such as the Capacitor Background Runner plugin or platform-specific plugins for geofencing and background location. These require extra manifest entries, iOS background modes and store justifications, and the platforms limit how often your code runs. Design Trailhead’s offline upload queue to resume when the app returns to the foreground first, and add background execution only if the product really needs it.
Swift Package Manager and CocoaPods
New Capacitor 8 iOS projects use Swift Package Manager by default, and plugins that ship a Swift package are linked through it. Projects that rely on plugins distributed only as CocoaPods can select the older mechanism:
npx cap add ios --packagemanager CocoaPods
With CocoaPods, open App.xcworkspace; with Swift Package Manager open App.xcodeproj. Do not mix the two in
one project, and run npx cap sync ios after every plugin change so the package manifest or Podfile is regenerated.
Upgrading Capacitor
Capacitor ships a migration command that updates the dependencies and native project files for a new major version:
npm install @capacitor/cli@latest @capacitor/core@latest
npx cap migrate
Commit your work first so the changes can be reviewed as a diff. Afterwards read the release’s upgrade guide for
the manual steps the command cannot perform (Xcode and Android Studio minimum versions, plugin major bumps), run
npx cap sync, and rebuild both platforms.
Summary
| Task | Where |
|---|---|
App identity and web folder |
|
Android permissions and intent filters |
|
iOS usage descriptions and capabilities |
|
Icons and splash |
|
Safe areas |
CSS |
Releasing |
See also Hybrid Apps: IDEs & Tools and the Ionic Cheat Sheet.