Using Mobile Native Capabilities
The lightning/mobileCapabilities module exposes a set of factory functions
that return service objects for native device features (barcode scanning,
biometrics, location, etc.). Each service extends a common
BaseCapability with an isAvailable()
method, so an LWC can degrade gracefully on surfaces where the capability is
not present (desktop, mobile web).
This skill routes an agent through (1) picking the right capability, (2)
loading the authoritative type definitions, and (3) wiring the service into
an LWC with the correct availability gating, error handling, and
deprecation-aware API choice.
When to Use This Skill
- User asks for an LWC that uses a device capability listed in the index
below.
- User mentions
lightning/mobileCapabilities, "mobile capability", or
"Nimbus" by name.
- User wants to know which mobile native APIs are available, or which one
fits their feature.
Do NOT use this skill for:
- Mobile-offline review of an LWC (lwc:if, inline GraphQL, Komaci-priming
violations) — use
mobile-platform-offline-validate.
- Choosing or styling generic Lightning Base Components / SLDS blueprints —
use
design-systems-slds-apply.
Prerequisites
- Knowledge that the LWC will run inside a supported mobile container
(Salesforce Mobile App, Field Service Mobile App). These capabilities are
unavailable on desktop and mobile web; gate every call behind
isAvailable().
- Familiarity with the
lightning/mobileCapabilities module declaration
(see mobile-capabilities).
Capability Index
| Capability |
Reference |
One-line use |
| App Review |
App Review |
Prompt the user for a native in-app review. |
| AR Space Capture |
AR Space Capture |
Capture a 3D scan of a physical space using AR. |
| Barcode Scanner |
Barcode Scanner |
Read QR / UPC / EAN / Code-128 / etc. from the camera. |
| Biometrics |
Biometrics |
Authenticate via Face ID / fingerprint. |
| Calendar |
Calendar |
Read or create events on the device calendar. |
| Contacts |
Contacts |
Read or create entries in the device address book. |
| Document Scanner |
Document Scanner |
Scan paper documents using the camera with edge detection. |
| Geofencing |
Geofencing |
Trigger logic when the device crosses a geographic boundary. |
| Location |
Location |
Read GPS coordinates and watch for updates. |
| NFC |
NFC |
Read or write NFC tags. |
| Payments |
Payments |
Take an Apple Pay / Google Pay payment. |
Workflow
Step 1 — Identify the capability
Map the user's feature ask to one row of the capability index. If the ask
spans multiple capabilities (e.g. "scan a barcode and store it on a
contact"), plan for each capability separately — there is one factory
function per capability.
Step 2 — Load the shared and capability-specific references
Read these two shared references once per session — they apply to every
capability and are not duplicated in the per-capability files:
- BaseCapability — the common interface
with
isAvailable() that every service extends.
- mobile-capabilities — the
lightning/mobileCapabilities module declaration showing every
re-exported service.
Then open the capability's reference file from the table above. Each
per-capability reference contains the service-specific TypeScript API
(factory function, service interface, options types, result types, error
types) and assumes the two shared references above are already in context.
Do not infer the API from memory — read it. The services evolve and some
methods are explicitly @deprecated in favor of newer alternatives.
Step 3 — Wire the service into the LWC
For each capability:
- Import the factory from
lightning/mobileCapabilities:import { getBarcodeScanner } from 'lightning/mobileCapabilities';
- Get an instance:
const scanner = getBarcodeScanner();
- Gate the call behind
isAvailable():if (!scanner.isAvailable()) {
// graceful fallback or user message
return;
}
- Call the non-deprecated entry point. Several services keep older
methods marked
@deprecated alongside the recommended one — always
prefer the recommended method in the reference.
- Wrap the promise in
try/catch and handle the typed failure codes the
service exposes (e.g. BarcodeScannerFailureCode,
LocationServiceFailureCode). User-cancelled vs. permission-denied vs.
service-unavailable are distinct UX states.
Step 4 — Surface failure modes to the user
Each service defines its own failure-code enum. Translate codes into
user-actionable messages: a USER_DENIED_PERMISSION should ask the user to
grant permission; a USER_DISABLED_PERMISSION must direct them to the OS
settings; a SERVICE_NOT_ENABLED should be a developer-visible error, not
shown to the user.
Step 5 — Stay inside the supported surface
Mobile capabilities are available only when the LWC runs inside a
supported Salesforce mobile app. If the same component is rendered on
desktop or mobile web, the factory will still return an object but
isAvailable() will return false. Never assume availability — gate every
call.
Examples
Example — "Scan a barcode and write it into a field"
- Map to: Barcode Scanner.
- Read Barcode Scanner.
- Use
scan(options) (not the deprecated beginCapture / resumeCapture
/ endCapture triple).
- In options, set the
barcodeTypes to the symbologies needed (default is
all supported types) and enableMultiScan: false for a single read.
- On resolve, write
result[0].value to the bound field. On reject,
inspect error.code against BarcodeScannerFailureCode.
Example — "Take an Apple Pay payment for an order total"
- Map to: Payments.
- Read Payments.
- Gate on
isAvailable().
- Build the payment request object per the reference.
- On resolve, surface the transaction id to the calling flow. On reject,
handle user-cancelled and payment-failed paths separately.
Verification Checklist
Troubleshooting
isAvailable() returns false on a real device — the device is
running an unsupported app surface (not Salesforce Mobile or Field
Service Mobile), or the service is gated by an org-level setting. The
fix is org configuration, not code.
- TypeScript can't find the import — confirm the LWC has access to
lightning/mobileCapabilities. The module is declared globally inside
Salesforce mobile containers; outside that, the types must be installed
separately.
- Deprecated barcode methods still work — yes, but new code must use
scan() and dismiss(). Refactor any sample code the agent received
before returning it.
- Multiple capabilities in one component — get separate instances per
capability (they are independent service objects); do not try to share
state between them.
1---2name: mobile-platform-native-capabilities-integrate3description: Build a Salesforce LWC that uses native mobile device capabilities — barcode scanner, biometrics, location, NFC, calendar, contacts, document scanner, geofencing, AR space capture, app review, and payments. Use this skill when the user asks for an LWC that scans a barcode, captures a photo of a document, reads location or geofences, prompts for biometrics, reads/writes the device calendar or contacts, taps NFC, takes a payment, prompts for an app review, or scans an AR space. Also triggers on "lightning/mobileCapabilities", "mobile capability", "Nimbus", "device capability". Do not use for mobile offline / Komaci priming reviews (use `mobile-platform-offline-validate`) or for picking generic Lightning base components (use `design-systems-slds-apply`).4---5
6# Using Mobile Native Capabilities
7
8The `lightning/mobileCapabilities` module exposes a set of factory functions
9that return service objects for native device features (barcode scanning,
10biometrics, location, etc.). Each service extends a common
11[BaseCapability](references/base-capability.md) with an `isAvailable()`
12method, so an LWC can degrade gracefully on surfaces where the capability is
13not present (desktop, mobile web).
14
15This skill routes an agent through (1) picking the right capability, (2)
16loading the authoritative type definitions, and (3) wiring the service into
17an LWC with the correct availability gating, error handling, and
18deprecation-aware API choice.
19
20## When to Use This Skill
21
22- User asks for an LWC that uses a device capability listed in the index
23 below.
24- User mentions `lightning/mobileCapabilities`, "mobile capability", or
25 "Nimbus" by name.
26- User wants to know which mobile native APIs are available, or which one
27 fits their feature.
28
29Do NOT use this skill for:
30
31- Mobile-offline review of an LWC (lwc:if, inline GraphQL, Komaci-priming
32 violations) — use `mobile-platform-offline-validate`.
33- Choosing or styling generic Lightning Base Components / SLDS blueprints —
34 use `design-systems-slds-apply`.
35
36## Prerequisites
37
38- Knowledge that the LWC will run inside a supported mobile container
39 (Salesforce Mobile App, Field Service Mobile App). These capabilities are
40 unavailable on desktop and mobile web; gate every call behind
41 `isAvailable()`.
42- Familiarity with the `lightning/mobileCapabilities` module declaration
43 (see [mobile-capabilities](references/mobile-capabilities.md)).
44
45## Capability Index
46
47| Capability | Reference | One-line use |
48| --- | --- | --- |
49| App Review | [App Review](references/app-review.md) | Prompt the user for a native in-app review. |
50| AR Space Capture | [AR Space Capture](references/ar-space-capture.md) | Capture a 3D scan of a physical space using AR. |
51| Barcode Scanner | [Barcode Scanner](references/barcode-scanner.md) | Read QR / UPC / EAN / Code-128 / etc. from the camera. |
52| Biometrics | [Biometrics](references/biometrics.md) | Authenticate via Face ID / fingerprint. |
53| Calendar | [Calendar](references/calendar.md) | Read or create events on the device calendar. |
54| Contacts | [Contacts](references/contacts.md) | Read or create entries in the device address book. |
55| Document Scanner | [Document Scanner](references/document-scanner.md) | Scan paper documents using the camera with edge detection. |
56| Geofencing | [Geofencing](references/geofencing.md) | Trigger logic when the device crosses a geographic boundary. |
57| Location | [Location](references/location.md) | Read GPS coordinates and watch for updates. |
58| NFC | [NFC](references/nfc.md) | Read or write NFC tags. |
59| Payments | [Payments](references/payments.md) | Take an Apple Pay / Google Pay payment. |
60
61## Workflow
62
63### Step 1 — Identify the capability
64
65Map the user's feature ask to one row of the capability index. If the ask
66spans multiple capabilities (e.g. "scan a barcode and store it on a
67contact"), plan for **each** capability separately — there is one factory
68function per capability.
69
70### Step 2 — Load the shared and capability-specific references
71
72Read these two shared references **once** per session — they apply to every
73capability and are not duplicated in the per-capability files:
74
75- [BaseCapability](references/base-capability.md) — the common interface
76 with `isAvailable()` that every service extends.
77- [mobile-capabilities](references/mobile-capabilities.md) — the
78 `lightning/mobileCapabilities` module declaration showing every
79 re-exported service.
80
81Then open the capability's reference file from the table above. Each
82per-capability reference contains the service-specific TypeScript API
83(factory function, service interface, options types, result types, error
84types) and assumes the two shared references above are already in context.
85
86Do not infer the API from memory — read it. The services evolve and some
87methods are explicitly `@deprecated` in favor of newer alternatives.
88
89### Step 3 — Wire the service into the LWC
90
91For each capability:
92
931. Import the factory from `lightning/mobileCapabilities`:
94 ```js
95 import { getBarcodeScanner } from 'lightning/mobileCapabilities';
96 ```
972. Get an instance: `const scanner = getBarcodeScanner();`
983. Gate the call behind `isAvailable()`:
99 ```js
100 if (!scanner.isAvailable()) {
101 // graceful fallback or user message
102 return;
103 }
104 ```
1054. Call the **non-deprecated** entry point. Several services keep older
106 methods marked `@deprecated` alongside the recommended one — always
107 prefer the recommended method in the reference.
1085. Wrap the promise in `try/catch` and handle the typed failure codes the
109 service exposes (e.g. `BarcodeScannerFailureCode`,
110 `LocationServiceFailureCode`). User-cancelled vs. permission-denied vs.
111 service-unavailable are distinct UX states.
112
113### Step 4 — Surface failure modes to the user
114
115Each service defines its own failure-code enum. Translate codes into
116user-actionable messages: a `USER_DENIED_PERMISSION` should ask the user to
117grant permission; a `USER_DISABLED_PERMISSION` must direct them to the OS
118settings; a `SERVICE_NOT_ENABLED` should be a developer-visible error, not
119shown to the user.
120
121### Step 5 — Stay inside the supported surface
122
123Mobile capabilities are available **only** when the LWC runs inside a
124supported Salesforce mobile app. If the same component is rendered on
125desktop or mobile web, the factory will still return an object but
126`isAvailable()` will return `false`. Never assume availability — gate every
127call.
128
129
130## Examples
131
132### Example — "Scan a barcode and write it into a field"
133
1341. Map to: Barcode Scanner.
1352. Read [Barcode Scanner](references/barcode-scanner.md).
1363. Use `scan(options)` (not the deprecated `beginCapture` / `resumeCapture`
137 / `endCapture` triple).
1384. In options, set the `barcodeTypes` to the symbologies needed (default is
139 all supported types) and `enableMultiScan: false` for a single read.
1405. On resolve, write `result[0].value` to the bound field. On reject,
141 inspect `error.code` against `BarcodeScannerFailureCode`.
142
143### Example — "Take an Apple Pay payment for an order total"
144
1451. Map to: Payments.
1462. Read [Payments](references/payments.md).
1473. Gate on `isAvailable()`.
1484. Build the payment request object per the reference.
1495. On resolve, surface the transaction id to the calling flow. On reject,
150 handle user-cancelled and payment-failed paths separately.
151
152
153## Verification Checklist
154
155- [ ] Every capability call is preceded by `isAvailable()`.
156- [ ] The non-deprecated entry point is used (no `beginCapture` /
157 `resumeCapture` / `endCapture` for barcode, etc.).
158- [ ] Each rejection path is mapped to the typed failure code enum.
159- [ ] Imports come from `lightning/mobileCapabilities`, not from a private
160 path.
161- [ ] No assumption that the capability runs on desktop or mobile web.
162
163
164## Troubleshooting
165
166- **`isAvailable()` returns `false` on a real device** — the device is
167 running an unsupported app surface (not Salesforce Mobile or Field
168 Service Mobile), or the service is gated by an org-level setting. The
169 fix is org configuration, not code.
170- **TypeScript can't find the import** — confirm the LWC has access to
171 `lightning/mobileCapabilities`. The module is declared globally inside
172 Salesforce mobile containers; outside that, the types must be installed
173 separately.
174- **Deprecated barcode methods still work** — yes, but new code must use
175 `scan()` and `dismiss()`. Refactor any sample code the agent received
176 before returning it.
177- **Multiple capabilities in one component** — get separate instances per
178 capability (they are independent service objects); do not try to share
179 state between them.