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.
npm install swizi
# Or with yarn
yarn add swizi
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
swizi
globally available.
await swizi.copyToClipboard("Hello World", true);
const platform = await swizi.getPlatform();
console.log(`Running on ${platform}`);
Copy text to clipboard.
await swizi.copyToClipboard("secret", true);
Connect to a secure or open Wifi network.
await swizi.connectToWifi("MySSID", "identity", "password", 1, "PEAP", "MSCHAPv2", false);
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();
await swizi.navigate("swz://views/home");
await swizi.goBack();
Opens the app settings on the device.
await swizi.openAppSettings();
await swizi.displayPopup("Alert", "Something went wrong");
await swizi.displayMenu("Options", [{ label: "Delete", color: "danger", event: "delete_item" }]);
Change the title of the current view.
await swizi.setViewTitle("My new title");
Set the action buttons on the current view.
await swizi.setViewActions([
{
icon: "business",
color: "primary_base",
event: "select_site",
badge: true,
},
]);
Returns "ios"
or "android"
.
Returns OS version object.
Returns current language: { lang: "fr" }
Retrieve the device's location. Returns { result: "success", lat, lon }
or { result: "location_unauthorized" }
.
const location = await swizi.getLocation(true);
console.log(location);
Returns { result: "success", lat, lon }
or { result: "location_unauthorized" }
await swizi.trackUserLocation();
await swizi.stopTrackUserLocation();
Returns the connected user object.
Returns current user JWT.
Returns plugin manifest + parsed configuration.
await swizi.sendStat("search", { query: "hello" });
downloadFile(url, fileName)
readQRCode(...)
getWifiInfos()
log(type, message)
openAppSettings()
share(content)
-
onEvent(listener)
/removeEvent(listener)
performGenericAction(actionID, params)