swizi
v6.8.2
Published
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.
Readme
Swizi JS SDK
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.
📦 Installation
npm install swizi
# Or with yarn
yarn add swizi🏁 Initialization
To use this package, simply import it once at the beginning of your app:
import("swizi");This will attach the swizi object to the global window object:
window.swizi.copyToClipboard("Hello", false);Note: you don't need to assign the result of the import. Just importing it will make
swiziglobally available.
🔧 Basic Usage
await swizi.copyToClipboard("Hello World", true);
const platform = await swizi.getPlatform();
console.log(`Running on ${platform}`);📘 API Documentation
Table of Contents
- 📋 Clipboard
- 🌐 Wifi & Network
- 📦 Storage
- 🧭 Navigation
- 💬 UI & Interaction
- 🌍 Device & App Info
- 📍 Location & Tracking
- 👤 User & Auth
- 📑 Manifest
- 📊 Analytics
- 🧩 Events & Logging
📋 Clipboard
copyToClipboard(text: string, sensitive: boolean): Promise<void>
Copy text to the clipboard. If sensitive is true, native code may treat the data as sensitive (e.g. avoid previews).
await swizi.copyToClipboard("secret", true);🌐 Wifi & Network
connectToWifi(ssid, identity, pwd, wifiSecurity, eapType, authType, captivePortal): Promise<object|null>
Connect to a secure or open Wifi network. Returns parsed JSON or null.
const result = await swizi.connectToWifi(
"MySSID",
"identity",
"password",
1,
"PEAP",
"MSCHAPv2",
false,
);
console.log(result);getWifiInfos(): Promise<object|null>
Get current Wifi network info (structure depends on platform).
const info = await swizi.getWifiInfos();📦 Storage
Namespaced Storage
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
await swizi.setItemForKey("hello", "greeting");
const value = await swizi.getItemForKey("greeting");🧭 Navigation
navigate(deeplink: string): Promise<void>
Navigate to a deep link.
await swizi.navigate("swz://views/home");goBack(): Promise<void>
Go back in the navigation stack.
await swizi.goBack();interceptBackNavigation(intercept = true): Promise<void>
Intercept native back navigation and route it to JS.
await swizi.interceptBackNavigation();performGenericAction(actionID: string, params?: object): Promise<void>
Trigger a generic action in the app.
await swizi.performGenericAction("openPlanning", { foo: "bar" });openAppSettings(): Promise<void>
Open the app settings on the device.
await swizi.openAppSettings();💬 UI & Interaction
displayPopup(title: string, content: string): Promise<void>
Show a popup dialog.
await swizi.displayPopup("Alert", "Something went wrong");displayMenu(title: string, actions: Array): Promise<void>
Show a menu or bottom sheet.
await swizi.displayMenu("Options", [{ label: "Delete", color: "danger", event: "delete_item" }]);setViewTitle(title: string): Promise<void>
Change the title of the current view.
await swizi.setViewTitle("My new title");setViewActions(actions: Array): Promise<void>
Set the action buttons on the current view.
await swizi.setViewActions([
{
icon: "business",
color: "primary_base",
event: "select_site",
badge: true,
},
]);readQRCode(title?: string, fullscreen?: boolean, multipleTimes?: boolean, action?: object): Promise<void>
Open a QR code scanner. Listen for results via events (see Events section).
await swizi.readQRCode("Scan code", false, false, { label: "Manual entry", event: "manual" });share(content: string): Promise<void>
Open the native share sheet.
await swizi.share("Check this out!");downloadFile(url: string, fileName: string): Promise<void>
Download a file natively.
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.
const color = await swizi.getColor("COLOR_BUTTON_BACK");getPrint(canvas?: string): Promise<string>
Send content to a Zebra printer.
const result = await swizi.getPrint(base64Image);🌍 Device & App Info
isPluginBridgeReady(): boolean
Returns true if a native bridge is available.
getPlatform(): Promise<"ios"|"android">
Returns platform string.
getPlatformVersion(): Promise<object|null>
Returns OS version object.
getVersion(): Promise<{version:string,buildNumber:string}|null>
Returns app version/build.
getManifest(): Promise<object|null>
Returns plugin manifest and parsed configuration.
getLang(): Promise<{lang:string}|null>
Returns current language.
📍 Location & Tracking
getLocation(forceRefresh?: boolean): Promise<{result:string,lat?:number,lon?:number}|null>
Get device location. Returns { result: "success", lat, lon } or { result: "location_unauthorized" }.
const location = await swizi.getLocation(true);trackUserLocation(): Promise<object|null>
Start continuous location tracking.
const status = await swizi.trackUserLocation();stopTrackUserLocation(): Promise<void>
Stop location tracking.
await swizi.stopTrackUserLocation();getUserLocation(): Promise<void>
Request a one-shot user location event (listen via onEvent).
👤 User & Auth
getUser(): Promise<object|null>
Returns the connected user object.
getToken(): Promise<string>
Returns current user JWT.
getUserPhoto(userId?: number): Promise<void>
Request user photo (event-based response).
📑 Manifest
See Device & App Info (getManifest).
📊 Analytics
sendStat(key: string, segmentation?: object): Promise<void>
Send an analytics/statistics event.
await swizi.sendStat("search", { query: "hello" });🧩 Events & Logging
onEvent(listener: function): void / removeEvent(listener: function): void
Subscribe/unsubscribe to native-originated events dispatched as swiziEvent on document.
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.
swizi.log("warn", "Something happened");Deprecated
setTitle() → use setViewTitle() instead.
Note: Many functions return parsed JSON objects. Event-based APIs emit
swiziEventwith payloads; inspectev.detailfor data.
