forcedotcom/sf-skills / plugins/builder/mobile-development/skills/mobile-platform-native-capabilities-integrate
mobile-platform-native-capabilities-integrate
VerifiedBuild 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`).
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 8.6 KB |
| references/app-review.md | markdown | 2.2 KB |
| references/ar-space-capture.md | markdown | 3.3 KB |
| references/barcode-scanner.md | markdown | 8.1 KB |
| references/base-capability.md | markdown | 651 B |
| references/biometrics.md | markdown | 3.9 KB |
| references/calendar.md | markdown | 7.3 KB |
| references/contacts.md | markdown | 6.9 KB |
| references/document-scanner.md | markdown | 9.7 KB |
| references/geofencing.md | markdown | 4.2 KB |
| references/location.md | markdown | 5.4 KB |
| references/mobile-capabilities.md | markdown | 2.1 KB |
| references/nfc.md | markdown | 7.5 KB |
| references/payments.md | markdown | 2.9 KB |
references/location.md
View on GitHub# Location Service Grounding Context
The following content provides grounding information for generating a Salesforce LWC that leverages location facilities on mobile devices. Specifically, this context will cover the API types and methods available to leverage the location API of the mobile device, within the LWC.
## Location Service API
```typescript
/*
* Copyright (c) 2024, Salesforce, Inc.
* All rights reserved.
* For full license text, see the LICENSE.txt file
*/
import { BaseCapability } from '../BaseCapability.js';
/**
* Use this factory function to get an instance of {@linkcode LocationService}.
* @returns An instance of {@linkcode LocationService}.
*/
export function getLocationService(): LocationService;
/**
* Access and track location in a Lightning web component.
* @see {@link https://developer.salesforce.com/docs/platform/lwc/guide/reference-lightning-locationservice.html|LocationService API}
*/
export interface LocationService extends BaseCapability {
/**
* Gets the device’s current geolocation.
* @param options A {@linkcode LocationServiceOptions} object to configure the location request.
* @returns A Promise object that resolves as a {@linkcode LocationResult} object with the device location details.
*/
getCurrentPosition(options?: LocationServiceOptions): Promise<LocationResult>;
/**
* Subscribes to asynchronous location updates for the mobile device.
* @param options A {@linkcode LocationServiceOptions} object to configure the location request.
* @param callback A function to handle location update responses.
* @returns An integer identifier for the location subscription, which you can use to end the subscription when you want to stop receiving location updates.
*/
startWatchingPosition(
options: LocationServiceOptions | null,
callback: (result?: LocationResult, failure?: LocationServiceFailure) => void,
): number;
/**
* Unsubscribes from location updates for the mobile device.
* @param watchId An integer identifier for an active location subscription, returned by a call to startWatchingPosition().
*/
stopWatchingPosition(watchId: number): void;
}
/**
* LocationResult interface.
*/
export interface LocationResult {
/**
* The physical location.
*/
coords: Coordinates;
/**
* The time of the location reading, measured in milliseconds since January 1, 1970.
*/
timestamp: number;
}
/**
* An object representing a specific point located on the planet Earth. Includes velocity details, if available.
* Includes accuracy information, to the best of the device’s ability to evaluate. Similar to a GeolocationCoordinates in the Geolocation Web API.
*/
export interface Coordinates {
/**
* The latitude, in degrees. Ranges from -90 to 90.
*/
latitude: number;
/**
* The longitude, in degrees. Ranges from -180 to 180.
*/
longitude: number;
/**
* Optional. Accuracy of the location measurement, in meters, as a radius around the measurement.
*/
accuracy?: number;
/**
* Optional. Meters above sea level.
*/
altitude?: number;
/**
* Optional. Accuracy of the altitude measurement, in meters.
*/
altitudeAccuracy?: number;
/**
* Optional. Velocity of motion, if any, in meters per second.
*/
speed?: number;
/**
* Optional. Accuracy of the speed measurement, in meters.
*/
speedAccuracy?: number;
/**
* Optional. Direction of motion, in degrees from true north. Ranges from 0 to 360.
*/
heading?: number;
/**
* Optional. Accuracy of the heading measurement, in degrees.
*/
headingAccuracy?: number; // accuracy for the heading in degree
}
/**
* An object representing an error that occurred when accessing LocationService features.
*/
export interface LocationServiceFailure {
/**
* A value representing the reason for a location error.
*/
code: LocationServiceFailureCode;
/**
* A string value explaining the reason for the failure. This value is suitable for use in user interface messages. The message is provided in English, and isn’t localized.
*/
message: string;
}
/**
* Possible failure codes.
*/
export type LocationServiceFailureCode =
| 'LOCATION_SERVICE_DISABLED' // Android only - The code when the location service is disabled on the device, not just for this app.
| 'USER_DENIED_PERMISSION' // Permission was denied by user when prompt, could ask again
| 'USER_DISABLED_PERMISSION' // Android: permission was denied along "don't ask again" when prompt, will need to go app setting to turn on. iOS: permission was disabled by the user and will need to be turned on in settings
| 'SERVICE_NOT_ENABLED' // The service is not enabled and therefore cannot be used.
| 'UNKNOWN_REASON'; // An error happened in the Native Code that is not permission based. Will give more information in the LocationServiceFailure message.
/**
* An object representing configuration details for a location service session.
*/
export interface LocationServiceOptions {
/**
* Whether to use high accuracy mode when determining location. Set to true to prioritize location accuracy.
* Set to false to prioritize battery life and response time.
*/
enableHighAccuracy: boolean;
/**
* Optional, and only for Android implementations. The text shown in the UI when the device prompts the user to grant permission for your app to use the Android's location service.
*/
permissionRationaleText?: string;
}
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |