or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

device-system.mdfile-system.mdhooks.mdindex.mdlocation-sensors.mdmedia.mdnavigation.mdnetwork.mdstorage.mdui-apis.md

device-system.mddocs/

0

# Device & System APIs

1

2

Device information, system capabilities, clipboard operations, vibration, phone calls, and authorization management for Taro React Native applications.

3

4

## Capabilities

5

6

### System Information

7

8

Access comprehensive device and system information.

9

10

```typescript { .api }

11

/**

12

* Get system information asynchronously

13

* @param options System info options

14

*/

15

function getSystemInfo(options?: {

16

success?: (res: SystemInfo) => void;

17

fail?: (res: TaroGeneral.CallbackResult) => void;

18

complete?: (res: any) => void;

19

}): Promise<SystemInfo>;

20

21

/**

22

* Get system information synchronously

23

* @returns System information

24

*/

25

function getSystemInfoSync(): SystemInfo;

26

27

interface SystemInfo {

28

brand: string;

29

model: string;

30

system: string;

31

platform: string;

32

version: string;

33

SDKVersion: string;

34

pixelRatio: number;

35

screenWidth: number;

36

screenHeight: number;

37

windowWidth: number;

38

windowHeight: number;

39

statusBarHeight: number;

40

safeArea: {

41

left: number;

42

right: number;

43

top: number;

44

bottom: number;

45

width: number;

46

height: number;

47

};

48

language: string;

49

fontSizeSetting: number;

50

}

51

```

52

53

**Usage Examples:**

54

55

```typescript

56

import { getSystemInfo, getSystemInfoSync } from "@tarojs/taro-rn";

57

58

// Get system info asynchronously

59

const systemInfo = await getSystemInfo();

60

console.log('Device brand:', systemInfo.brand);

61

console.log('Screen dimensions:', systemInfo.screenWidth, 'x', systemInfo.screenHeight);

62

console.log('Safe area:', systemInfo.safeArea);

63

64

// Get system info synchronously

65

const syncSystemInfo = getSystemInfoSync();

66

console.log('Platform:', syncSystemInfo.platform);

67

68

// Adapt UI based on device info

69

if (syncSystemInfo.screenWidth < 400) {

70

console.log('Small screen detected, use compact layout');

71

}

72

```

73

74

### App Information

75

76

Get basic application information.

77

78

```typescript { .api }

79

/**

80

* Get app base information

81

* @param options App info options

82

*/

83

function getAppBaseInfo(options?: {

84

success?: (res: {

85

SDKVersion: string;

86

enableDebug: boolean;

87

host: any;

88

language: string;

89

version: string;

90

theme: string;

91

}) => void;

92

fail?: (res: TaroGeneral.CallbackResult) => void;

93

complete?: (res: any) => void;

94

}): Promise<{

95

SDKVersion: string;

96

enableDebug: boolean;

97

host: any;

98

language: string;

99

version: string;

100

theme: string;

101

}>;

102

```

103

104

### Vibration

105

106

Control device vibration for haptic feedback.

107

108

```typescript { .api }

109

/**

110

* Trigger a long vibration (400ms)

111

* @param options Long vibration options

112

*/

113

function vibrateLong(options?: {

114

success?: (res: TaroGeneral.CallbackResult) => void;

115

fail?: (res: TaroGeneral.CallbackResult) => void;

116

complete?: (res: TaroGeneral.CallbackResult) => void;

117

}): Promise<TaroGeneral.CallbackResult>;

118

119

/**

120

* Trigger a short vibration (15ms)

121

* @param options Short vibration options

122

*/

123

function vibrateShort(options?: {

124

type?: 'heavy' | 'medium' | 'light';

125

success?: (res: TaroGeneral.CallbackResult) => void;

126

fail?: (res: TaroGeneral.CallbackResult) => void;

127

complete?: (res: TaroGeneral.CallbackResult) => void;

128

}): Promise<TaroGeneral.CallbackResult>;

129

```

130

131

**Usage Examples:**

132

133

```typescript

134

import { vibrateLong, vibrateShort } from "@tarojs/taro-rn";

135

136

// Long vibration for notifications

137

await vibrateLong();

138

139

// Short vibration for button taps

140

await vibrateShort({ type: 'light' });

141

142

// Medium vibration for feedback

143

await vibrateShort({ type: 'medium' });

144

```

145

146

### Clipboard Operations

147

148

Manage clipboard data for copy/paste functionality.

149

150

```typescript { .api }

151

/**

152

* Set data to clipboard

153

* @param options Clipboard set options

154

*/

155

function setClipboardData(options: {

156

data: string;

157

success?: (res: TaroGeneral.CallbackResult) => void;

158

fail?: (res: TaroGeneral.CallbackResult) => void;

159

complete?: (res: TaroGeneral.CallbackResult) => void;

160

}): Promise<TaroGeneral.CallbackResult>;

161

162

/**

163

* Get data from clipboard

164

* @param options Clipboard get options

165

*/

166

function getClipboardData(options?: {

167

success?: (res: { data: string }) => void;

168

fail?: (res: TaroGeneral.CallbackResult) => void;

169

complete?: (res: any) => void;

170

}): Promise<{ data: string }>;

171

```

172

173

**Usage Examples:**

174

175

```typescript

176

import { setClipboardData, getClipboardData } from "@tarojs/taro-rn";

177

178

// Copy text to clipboard

179

await setClipboardData({

180

data: 'Hello, this text is now in clipboard!'

181

});

182

183

// Get text from clipboard

184

const clipboardResult = await getClipboardData();

185

console.log('Clipboard content:', clipboardResult.data);

186

187

// Copy complex data (as JSON string)

188

const userData = { id: 123, name: 'John Doe' };

189

await setClipboardData({

190

data: JSON.stringify(userData)

191

});

192

```

193

194

### Phone Call

195

196

Initiate phone calls from the application.

197

198

```typescript { .api }

199

/**

200

* Make a phone call

201

* @param options Phone call options

202

*/

203

function makePhoneCall(options: {

204

phoneNumber: string;

205

success?: (res: TaroGeneral.CallbackResult) => void;

206

fail?: (res: TaroGeneral.CallbackResult) => void;

207

complete?: (res: TaroGeneral.CallbackResult) => void;

208

}): Promise<TaroGeneral.CallbackResult>;

209

```

210

211

**Usage Examples:**

212

213

```typescript

214

import { makePhoneCall } from "@tarojs/taro-rn";

215

216

// Make a phone call

217

await makePhoneCall({

218

phoneNumber: '+1234567890'

219

});

220

221

// Handle call with error handling

222

try {

223

await makePhoneCall({ phoneNumber: '911' });

224

} catch (error) {

225

console.error('Failed to make call:', error);

226

}

227

```

228

229

### QR Code Scanning

230

231

Scan QR codes and barcodes using the device camera.

232

233

```typescript { .api }

234

/**

235

* Scan QR code or barcode

236

* @param options Scan code options

237

*/

238

function scanCode(options?: {

239

onlyFromCamera?: boolean;

240

scanType?: ('barCode' | 'qrCode' | 'datamatrix' | 'pdf417')[];

241

success?: (res: {

242

result: string;

243

scanType: string;

244

charSet: string;

245

path: string;

246

}) => void;

247

fail?: (res: TaroGeneral.CallbackResult) => void;

248

complete?: (res: any) => void;

249

}): Promise<{

250

result: string;

251

scanType: string;

252

charSet: string;

253

path: string;

254

}>;

255

```

256

257

**Usage Examples:**

258

259

```typescript

260

import { scanCode } from "@tarojs/taro-rn";

261

262

// Scan QR code

263

const scanResult = await scanCode({

264

onlyFromCamera: true,

265

scanType: ['qrCode']

266

});

267

268

console.log('Scanned result:', scanResult.result);

269

console.log('Scan type:', scanResult.scanType);

270

271

// Scan multiple types

272

const multiScanResult = await scanCode({

273

scanType: ['qrCode', 'barCode', 'datamatrix']

274

});

275

```

276

277

### Settings & Authorization

278

279

Manage app settings and request permissions.

280

281

```typescript { .api }

282

/**

283

* Open system settings page

284

* @param options Open settings options

285

*/

286

function openSetting(options?: {

287

success?: (res: {

288

authSetting: Record<string, boolean>;

289

}) => void;

290

fail?: (res: TaroGeneral.CallbackResult) => void;

291

complete?: (res: any) => void;

292

}): Promise<{

293

authSetting: Record<string, boolean>;

294

}>;

295

296

/**

297

* Get current app authorization settings

298

* @param options Get settings options

299

*/

300

function getSetting(options?: {

301

success?: (res: {

302

authSetting: Record<string, boolean>;

303

}) => void;

304

fail?: (res: TaroGeneral.CallbackResult) => void;

305

complete?: (res: any) => void;

306

}): Promise<{

307

authSetting: Record<string, boolean>;

308

}>;

309

310

/**

311

* Request user authorization

312

* @param options Authorization options

313

*/

314

function authorize(options: {

315

scope: string;

316

success?: (res: TaroGeneral.CallbackResult) => void;

317

fail?: (res: TaroGeneral.CallbackResult) => void;

318

complete?: (res: TaroGeneral.CallbackResult) => void;

319

}): Promise<TaroGeneral.CallbackResult>;

320

```

321

322

**Usage Examples:**

323

324

```typescript

325

import { getSetting, openSetting, authorize } from "@tarojs/taro-rn";

326

327

// Check current settings

328

const settings = await getSetting();

329

console.log('Auth settings:', settings.authSetting);

330

331

// Request camera permission

332

try {

333

await authorize({ scope: 'scope.camera' });

334

console.log('Camera permission granted');

335

} catch (error) {

336

console.log('Camera permission denied');

337

338

// Open settings page for user to manually enable

339

await openSetting();

340

}

341

342

// Check specific permissions

343

const currentSettings = await getSetting();

344

if (currentSettings.authSetting['scope.camera']) {

345

console.log('Camera permission is granted');

346

} else {

347

console.log('Camera permission is not granted');

348

}

349

```

350

351

### Environment & Capability Detection

352

353

Check environment and API availability.

354

355

```typescript { .api }

356

/**

357

* Get current environment type

358

* @returns Environment type

359

*/

360

function getEnv(): 'WEB' | 'RN' | 'WEAPP' | 'SWAN' | 'ALIPAY' | 'TT' | 'QQ' | 'JD';

361

362

/**

363

* Check if an API is available in current environment

364

* @param schema API schema to check

365

* @returns Whether the API is available

366

*/

367

function canIUse(schema: string): boolean;

368

```

369

370

**Usage Examples:**

371

372

```typescript

373

import { getEnv, canIUse } from "@tarojs/taro-rn";

374

375

// Check current environment

376

const env = getEnv();

377

console.log('Current environment:', env);

378

379

// Adapt behavior based on environment

380

if (env === 'RN') {

381

console.log('Running in React Native');

382

} else if (env === 'WEB') {

383

console.log('Running in browser');

384

}

385

386

// Check API availability

387

if (canIUse('getLocation')) {

388

console.log('Location API is available');

389

} else {

390

console.log('Location API is not available');

391

}

392

393

// Check specific API features

394

if (canIUse('showToast.image')) {

395

console.log('Toast with custom image is supported');

396

}

397

```

398

399

### User Profile

400

401

Get user profile information (platform-specific).

402

403

```typescript { .api }

404

/**

405

* Get user profile information

406

* @param options User profile options

407

*/

408

function getUserProfile(options: {

409

desc: string;

410

lang?: 'en' | 'zh_CN' | 'zh_TW';

411

success?: (res: {

412

userInfo: {

413

nickName: string;

414

avatarUrl: string;

415

gender: 0 | 1 | 2;

416

country: string;

417

province: string;

418

city: string;

419

language: string;

420

};

421

rawData: string;

422

signature: string;

423

encryptedData: string;

424

iv: string;

425

}) => void;

426

fail?: (res: TaroGeneral.CallbackResult) => void;

427

complete?: (res: any) => void;

428

}): Promise<{

429

userInfo: {

430

nickName: string;

431

avatarUrl: string;

432

gender: 0 | 1 | 2;

433

country: string;

434

province: string;

435

city: string;

436

language: string;

437

};

438

rawData: string;

439

signature: string;

440

encryptedData: string;

441

iv: string;

442

}>;

443

```