A runtime library for uni-app's app-plus platform, which provides mobile app functionality for the uni-app cross-platform framework
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Comprehensive device information, sensors, system capabilities, and hardware integration APIs.
Retrieve detailed system and device information.
/**
* Get system information asynchronously
* @param options - Options with success/fail callbacks
*/
function getSystemInfo(options?: GetSystemInfoOptions): void;
/**
* Get system information synchronously
* @returns System information object
*/
function getSystemInfoSync(): SystemInfo;
interface GetSystemInfoOptions {
success?: (result: SystemInfo) => void;
fail?: (error: any) => void;
complete?: () => void;
}
interface SystemInfo {
brand: string;
model: string;
system: string;
platform: string;
version: string;
SDKVersion?: string;
screenWidth: number;
screenHeight: number;
windowWidth: number;
windowHeight: number;
statusBarHeight: number;
pixelRatio: number;
fontSizeSetting: number;
language: string;
deviceOrientation: 'portrait' | 'landscape';
devicePixelRatio: number;
benchmarkLevel?: number;
albumAuthorized?: boolean;
cameraAuthorized?: boolean;
locationAuthorized?: boolean;
microphoneAuthorized?: boolean;
notificationAuthorized?: boolean;
[key: string]: any;
}Usage Examples:
import uni from "@dcloudio/uni-app-plus";
// Async system info
uni.getSystemInfo({
success: (res) => {
console.log('Device:', res.brand, res.model);
console.log('System:', res.system);
console.log('Screen size:', res.screenWidth, 'x', res.screenHeight);
}
});
// Sync system info
try {
const systemInfo = uni.getSystemInfoSync();
console.log('Platform:', systemInfo.platform);
} catch (error) {
console.error('Failed to get system info:', error);
}Check if specific APIs or features are available on the current platform.
/**
* Check if API/component is available
* @param schema - API name or capability string
* @returns true if available
*/
function canIUse(schema: string): boolean;Usage Examples:
// Check API availability
if (uni.canIUse('getLocation')) {
uni.getLocation({
success: (res) => {
console.log('Location:', res.latitude, res.longitude);
}
});
}
// Check component capability
if (uni.canIUse('button.open-type.share')) {
// Share button is supported
}
// Check method capability
if (uni.canIUse('showToast.object.image')) {
// showToast supports image parameter
}Monitor network connectivity and type.
/**
* Get current network type
* @param options - Options with success/fail callbacks
*/
function getNetworkType(options?: GetNetworkTypeOptions): void;
/**
* Listen for network status changes
* @param callback - Callback function
*/
function onNetworkStatusChange(callback: (result: NetworkStatusResult) => void): void;
/**
* Remove network status change listener
* @param callback - Callback function to remove
*/
function offNetworkStatusChange(callback: Function): void;
interface GetNetworkTypeOptions {
success?: (result: NetworkTypeResult) => void;
fail?: (error: any) => void;
complete?: () => void;
}
interface NetworkTypeResult {
networkType: 'wifi' | '2g' | '3g' | '4g' | '5g' | 'ethernet' | 'unknown' | 'none';
}
interface NetworkStatusResult {
isConnected: boolean;
networkType: string;
}Make phone calls and handle communication features.
/**
* Make a phone call
* @param options - Phone call options
*/
function makePhoneCall(options: MakePhoneCallOptions): void;
interface MakePhoneCallOptions {
phoneNumber: string;
success?: (result: any) => void;
fail?: (error: any) => void;
complete?: () => void;
}Usage Example:
uni.makePhoneCall({
phoneNumber: '+1234567890',
success: () => {
console.log('Phone call initiated');
},
fail: (error) => {
console.error('Failed to make call:', error);
}
});Scan QR codes and barcodes using the device camera.
/**
* Scan QR code or barcode
* @param options - Scan options
*/
function scanCode(options?: ScanCodeOptions): void;
interface ScanCodeOptions {
onlyFromCamera?: boolean;
scanType?: ('barCode' | 'qrCode')[];
autoDecodeCharSet?: boolean;
autoZoom?: boolean;
success?: (result: ScanCodeResult) => void;
fail?: (error: any) => void;
complete?: () => void;
}
interface ScanCodeResult {
result: string;
scanType: 'QR_CODE' | 'AZTEC' | 'CODABAR' | 'CODE_39' | 'CODE_93' | 'CODE_128' | 'DATA_MATRIX' | 'EAN_8' | 'EAN_13' | 'ITF' | 'MAXICODE' | 'PDF_417' | 'RSS_14' | 'RSS_EXPANDED' | 'UPC_A' | 'UPC_E' | 'UPC_EAN_EXTENSION';
charSet: string;
path: string;
}Read and write clipboard data.
/**
* Set clipboard data
* @param options - Clipboard data options
*/
function setClipboardData(options: SetClipboardDataOptions): void;
/**
* Get clipboard data
* @param options - Options with success/fail callbacks
*/
function getClipboardData(options?: GetClipboardDataOptions): void;
interface SetClipboardDataOptions {
data: string;
success?: (result: any) => void;
fail?: (error: any) => void;
complete?: () => void;
}
interface GetClipboardDataOptions {
success?: (result: ClipboardDataResult) => void;
fail?: (error: any) => void;
complete?: () => void;
}
interface ClipboardDataResult {
data: string;
}Control screen brightness and keep-alive functionality.
/**
* Set screen brightness
* @param options - Brightness options
*/
function setScreenBrightness(options: SetScreenBrightnessOptions): void;
/**
* Get screen brightness
* @param options - Options with success/fail callbacks
*/
function getScreenBrightness(options?: GetScreenBrightnessOptions): void;
/**
* Keep screen on or allow it to sleep
* @param options - Keep screen on options
*/
function setKeepScreenOn(options: SetKeepScreenOnOptions): void;
interface SetScreenBrightnessOptions {
value: number; // 0-1
success?: (result: any) => void;
fail?: (error: any) => void;
complete?: () => void;
}
interface SetKeepScreenOnOptions {
keepScreenOn: boolean;
success?: (result: any) => void;
fail?: (error: any) => void;
complete?: () => void;
}Control device vibration patterns.
/**
* Long vibration (400ms)
* @param options - Options with success/fail callbacks
*/
function vibrateLong(options?: VibrationOptions): void;
/**
* Short vibration (15ms)
* @param options - Options with success/fail callbacks
*/
function vibrateShort(options?: VibrationOptions): void;
interface VibrationOptions {
success?: (result: any) => void;
fail?: (error: any) => void;
complete?: () => void;
}Access device sensors including accelerometer, compass, and gyroscope.
/**
* Listen for accelerometer data changes
* @param callback - Callback function
*/
function onAccelerometerChange(callback: (result: AccelerometerResult) => void): void;
/**
* Remove accelerometer change listener
* @param callback - Callback function to remove
*/
function offAccelerometerChange(callback: Function): void;
/**
* Start accelerometer
* @param options - Accelerometer options
*/
function startAccelerometer(options?: AccelerometerOptions): void;
/**
* Stop accelerometer
* @param options - Options with success/fail callbacks
*/
function stopAccelerometer(options?: BaseOptions): void;
interface AccelerometerResult {
x: number;
y: number;
z: number;
}
interface AccelerometerOptions {
interval?: 'game' | 'ui' | 'normal';
success?: (result: any) => void;
fail?: (error: any) => void;
complete?: () => void;
}Usage Example:
// Start listening to accelerometer
uni.startAccelerometer({
interval: 'game',
success: () => {
console.log('Accelerometer started');
}
});
uni.onAccelerometerChange((res) => {
console.log('Acceleration:', res.x, res.y, res.z);
});
// Stop when no longer needed
uni.stopAccelerometer();Access device compass for direction information.
/**
* Listen for compass data changes
* @param callback - Callback function
*/
function onCompassChange(callback: (result: CompassResult) => void): void;
/**
* Start compass
* @param options - Options with success/fail callbacks
*/
function startCompass(options?: BaseOptions): void;
/**
* Stop compass
* @param options - Options with success/fail callbacks
*/
function stopCompass(options?: BaseOptions): void;
interface CompassResult {
direction: number; // 0-360 degrees
accuracy: number;
}Monitor memory usage and warnings.
/**
* Listen for memory warnings
* @param callback - Callback function
*/
function onMemoryWarning(callback: (result: MemoryWarningResult) => void): void;
interface MemoryWarningResult {
level: number; // Warning level 5/10/15
}Get device battery status and level.
/**
* Get battery information asynchronously
* @param options - Options with success/fail callbacks
*/
function getBatteryInfo(options: GetBatteryInfoOptions): void;
/**
* Get battery information synchronously
* @returns Battery information object
*/
function getBatteryInfoSync(): BatteryInfo;
interface GetBatteryInfoOptions {
success?: (result: BatteryInfo) => void;
fail?: (error: any) => void;
complete?: () => void;
}
interface BatteryInfo {
level: number; // Battery level percentage 0-100
isCharging: boolean; // Whether device is charging
}Add contacts to the device's phonebook.
/**
* Add a contact to the device phonebook
* @param options - Contact information and options
*/
function addPhoneContact(options: AddPhoneContactOptions): void;
interface AddPhoneContactOptions {
photoFilePath?: string;
nickName?: string;
lastName?: string;
middleName?: string;
firstName: string;
remark?: string;
mobilePhoneNumber?: string;
weChatNumber?: string;
addressCountry?: string;
addressState?: string;
addressCity?: string;
addressStreet?: string;
addressPostalCode?: string;
organization?: string;
title?: string;
workFaxNumber?: string;
workPhoneNumber?: string;
hostNumber?: string;
email?: string;
url?: string;
workAddressCountry?: string;
workAddressState?: string;
workAddressCity?: string;
workAddressStreet?: string;
workAddressPostalCode?: string;
homeFaxNumber?: string;
homePhoneNumber?: string;
homeAddressCountry?: string;
homeAddressState?: string;
homeAddressCity?: string;
homeAddressStreet?: string;
homeAddressPostalCode?: string;
success?: (result: any) => void;
fail?: (error: any) => void;
complete?: () => void;
}Usage Examples:
// Get battery status
uni.getBatteryInfo({
success(result) {
console.log('Battery level:', result.level + '%');
console.log('Charging:', result.isCharging);
if (result.level < 20 && !result.isCharging) {
uni.showToast({
title: 'Low battery warning',
icon: 'none'
});
}
}
});
// Add contact to phonebook
uni.addPhoneContact({
firstName: 'John',
lastName: 'Doe',
mobilePhoneNumber: '+1234567890',
email: 'john.doe@example.com',
organization: 'Example Corp',
success() {
uni.showToast({
title: 'Contact added successfully',
icon: 'success'
});
},
fail(error) {
console.error('Failed to add contact:', error);
}
});interface BaseOptions {
success?: (result: any) => void;
fail?: (error: any) => void;
complete?: () => void;
}
interface GetScreenBrightnessOptions {
success?: (result: ScreenBrightnessResult) => void;
fail?: (error: any) => void;
complete?: () => void;
}
interface ScreenBrightnessResult {
value: number; // 0-1
}