The Swizi sdk provides a way to access native methods such as retrieve the user, call generic actions or even getting a bar code inside your web plugin.
This package provides a JavaScript interface to interact with native Swizi features on mobile devices (iOS/Android). It exposes a unified API for calling native capabilities such as clipboard, navigation, storage, geolocation, and more.
``bash`
npm install swiziOr with yarn
yarn add swizi
To use this package, simply import it once at the beginning of your app:
`js`
import("swizi");
This will attach the swizi object to the global window object:
`js`
window.swizi.copyToClipboard("Hello", false);
> Note: you don't need to assign the result of the import. Just importing it will make swizi globally available.
`js
await swizi.copyToClipboard("Hello World", true);
const platform = await swizi.getPlatform();
console.log(Running on ${platform});`
- 📋 Clipboard
- 🌐 Wifi & Network
- 📦 Storage
- 🧭 Navigation
- 💬 UI & Interaction
- 🌍 Device & App Info
- 📍 Location & Tracking
- 👤 User & Auth
- 📑 Manifest
- 📊 Analytics
- 🧩 Events & Logging
#### copyToClipboard(text: string, sensitive: boolean): Promise
Copy text to the clipboard. If sensitive is true, native code may treat the data as sensitive (e.g. avoid previews).
`js`
await swizi.copyToClipboard("secret", true);
---
#### connectToWifi(ssid, identity, pwd, wifiSecurity, eapType, authType, captivePortal): Promise
Connect to a secure or open Wifi network. Returns parsed JSON or null.
`js`
const result = await swizi.connectToWifi(
"MySSID",
"identity",
"password",
1,
"PEAP",
"MSCHAPv2",
false,
);
console.log(result);
#### getWifiInfos(): Promise
Get current Wifi network info (structure depends on platform).
`js`
const info = await swizi.getWifiInfos();
---
#### Namespaced Storage
`js`
const storage = swizi.createStorage("plugin_");
await storage.setItem("foo", "bar");
const value = await storage.getItem("foo");
await storage.removeItem("foo");
await storage.clear();
const allKeys = await storage.keys();
#### Global Key/Value
`js`
await swizi.setItemForKey("hello", "greeting");
const value = await swizi.getItemForKey("greeting");
---
#### navigate(deeplink: string): Promise
Navigate to a deep link.
`js`
await swizi.navigate("swz://views/home");
#### goBack(): Promise
Go back in the navigation stack.
`js`
await swizi.goBack();
#### interceptBackNavigation(intercept = true): Promise
Intercept native back navigation and route it to JS.
`js`
await swizi.interceptBackNavigation();
#### performGenericAction(actionID: string, params?: object): Promise
Trigger a generic action in the app.
`js`
await swizi.performGenericAction("openPlanning", { foo: "bar" });
#### openAppSettings(): Promise
Open the app settings on the device.
`js`
await swizi.openAppSettings();
---
#### displayPopup(title: string, content: string): Promise
Show a popup dialog.
`js`
await swizi.displayPopup("Alert", "Something went wrong");
#### displayMenu(title: string, actions: Array): Promise
Show a menu or bottom sheet.
`js`
await swizi.displayMenu("Options", [{ label: "Delete", color: "danger", event: "delete_item" }]);
#### setViewTitle(title: string): Promise
Change the title of the current view.
`js`
await swizi.setViewTitle("My new title");
#### setViewActions(actions: Array): Promise
Set the action buttons on the current view.
`js`
await swizi.setViewActions([
{
icon: "business",
color: "primary_base",
event: "select_site",
badge: true,
},
]);
#### readQRCode(title?: string, fullscreen?: boolean, multipleTimes?: boolean, action?: object): Promise
Open a QR code scanner. Listen for results via events (see Events section).
`js`
await swizi.readQRCode("Scan code", false, false, { label: "Manual entry", event: "manual" });
#### share(content: string): Promise
Open the native share sheet.
`js`
await swizi.share("Check this out!");
#### downloadFile(url: string, fileName: string): Promise
Download a file natively.
`js`
await swizi.downloadFile("https://example.com/file.pdf", "file.pdf");
#### getColor(colorName: string): Promise<{r:number,g:number,b:number,a:number}|null>
Get a named color as RGBA.
`js`
const color = await swizi.getColor("COLOR_BUTTON_BACK");
#### getPrint(canvas?: string): Promise
Send content to a Zebra printer.
`js`
const result = await swizi.getPrint(base64Image);
---
#### isPluginBridgeReady(): boolean
Returns true if a native bridge is available.
#### getPlatform(): Promise<"ios"|"android">
Returns platform string.
#### getPlatformVersion(): Promise
Returns OS version object.
#### getVersion(): Promise<{version:string,buildNumber:string}|null>
Returns app version/build.
#### getManifest(): Promise
Returns plugin manifest and parsed configuration.
#### getLang(): Promise<{lang:string}|null>
Returns current language.
---
#### getLocation(forceRefresh?: boolean): Promise<{result:string,lat?:number,lon?:number}|null>
Get device location. Returns { result: "success", lat, lon } or { result: "location_unauthorized" }.
`js`
const location = await swizi.getLocation(true);
#### trackUserLocation(): Promise
Start continuous location tracking.
`js`
const status = await swizi.trackUserLocation();
#### stopTrackUserLocation(): Promise
Stop location tracking.
`js`
await swizi.stopTrackUserLocation();
#### getUserLocation(): Promise
Request a one-shot user location event (listen via onEvent).
---
#### getUser(): Promise
Returns the connected user object.
#### getToken(): Promise
Returns current user JWT.
#### getUserPhoto(userId?: number): Promise
Request user photo (event-based response).
---
See Device & App Info (getManifest).
---
#### sendStat(key: string, segmentation?: object): Promise
Send an analytics/statistics event.
`js`
await swizi.sendStat("search", { query: "hello" });
---
#### onEvent(listener: function): void / removeEvent(listener: function): void
Subscribe/unsubscribe to native-originated events dispatched as swiziEvent on document.
`js`
const handler = (ev) => {
console.log("Swizi event", ev.detail);
};
swizi.onEvent(handler);
swizi.removeEvent(handler);
Common emitters: readQRCode, getUserPhoto, getUserLocation, trackUserLocation.
#### log(type: "log"|"warn"|"error", message: string): void
Console logging helper.
`js`
swizi.log("warn", "Something happened");
#### Deprecated
setTitle() → use setViewTitle() instead.
---
> Note: Many functions return parsed JSON objects. Event-based APIs emit swiziEvent with payloads; inspect ev.detail` for data.