diff --git a/zh-cn/application-dev/file-management/app-file-access.md b/zh-cn/application-dev/file-management/app-file-access.md index eb3e5e4cdb3bc679242fef8f6fa0805cc9a9315a..026b546ebc4aa5fc7ee93283e57c7c6e3bd6d33b 100644 --- a/zh-cn/application-dev/file-management/app-file-access.md +++ b/zh-cn/application-dev/file-management/app-file-access.md @@ -48,12 +48,12 @@ import fs from '@ohos.file.fs'; import common from '@ohos.app.ability.common'; import buffer from '@ohos.buffer'; -createFile() { - // 获取应用文件路径 - let context = getContext(this) as common.UIAbilityContext; - let filesDir = context.filesDir; +// 获取应用文件路径 +let context = getContext(this) as common.UIAbilityContext; +let filesDir = context.filesDir; - // 新建并打开文件 +function createFile() { + // 新建并打开文件 let file = fs.openSync(filesDir + '/test.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); // 写入一段内容至文件 let writeLen = fs.writeSync(file.fd, "Try to write str."); @@ -77,11 +77,11 @@ createFile() { import fs from '@ohos.file.fs'; import common from '@ohos.app.ability.common'; -readWriteFile() { - // 获取应用文件路径 - let context = getContext(this) as common.UIAbilityContext; - let filesDir = context.filesDir; +// 获取应用文件路径 +let context = getContext(this) as common.UIAbilityContext; +let filesDir = context.filesDir; +function readWriteFile() { // 打开文件 let srcFile = fs.openSync(filesDir + '/test.txt', fs.OpenMode.READ_WRITE); let destFile = fs.openSync(filesDir + '/destFile.txt', fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); @@ -114,11 +114,11 @@ readWriteFile() { import fs from '@ohos.file.fs'; import common from '@ohos.app.ability.common'; -async readWriteFileWithStream() { - // 获取应用文件路径 - let context = getContext(this) as common.UIAbilityContext; - let filesDir = context.filesDir; +// 获取应用文件路径 +let context = getContext(this) as common.UIAbilityContext; +let filesDir = context.filesDir; +async readWriteFileWithStream() { // 打开文件流 let inputStream = fs.createStreamSync(filesDir + '/test.txt', 'r+'); let outputStream = fs.createStreamSync(filesDir + '/destFile.txt', "w+"); @@ -148,7 +148,6 @@ async readWriteFileWithStream() { 以下示例代码演示了如何查看文件列表: ```ts -// 查看文件列表 import fs, { Filter } from '@ohos.file.fs'; import common from '@ohos.app.ability.common'; @@ -157,7 +156,7 @@ let context = getContext(this) as common.UIAbilityContext; let filesDir = context.filesDir; // 查看文件列表 -getListFile() { +function getListFile() { let filter: Filter = { suffix: ['.png', '.jpg', '.txt'], // 匹配文件后缀名为'.png','.jpg','.txt' displayName: ['test%'], // 匹配文件全名以'test'开头 diff --git a/zh-cn/application-dev/file-management/app-file-backup.md b/zh-cn/application-dev/file-management/app-file-backup.md index 1928f6c4366748687bfa46702876d96b91ec5d29..84b77faec5625e0259e83772423cb45b31319cbd 100644 --- a/zh-cn/application-dev/file-management/app-file-backup.md +++ b/zh-cn/application-dev/file-management/app-file-backup.md @@ -33,16 +33,24 @@ 调用`backup.getLocalCapabilities()`获取能力文件。 ```ts + import backup from '@ohos.file.backup'; + import common from '@ohos.app.ability.common'; import fs from '@ohos.file.fs'; + + // 获取应用文件路径 + let context = getContext(this) as common.UIAbilityContext; + let filesDir = context.filesDir; + async function getLocalCapabilities() { try { let fileData = await backup.getLocalCapabilities(); console.info('getLocalCapabilities success'); - let fpath = await globalThis.context.filesDir + '/localCapabilities.json'; + let fpath = filesDir + '/localCapabilities.json'; fs.copyFileSync(fileData.fd, fpath); fs.closeSync(fileData.fd); - } catch (err) { - console.error('getLocalCapabilities failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('getLocalCapabilities failed with err: ' + JSON.stringify(err)); } } ``` @@ -88,19 +96,21 @@ **示例** ```ts - import fs from '@ohos.file.fs'; + import backup from '@ohos.file.backup'; import common from '@ohos.app.ability.common'; + import fs from '@ohos.file.fs'; import { BusinessError } from '@ohos.base'; + // 获取沙箱路径 let context = getContext(this) as common.UIAbilityContext; let filesDir = context.filesDir; // 创建SessionBackup类的实例用于备份数据 let g_session: backup.SessionBackup; - createSessionBackup() { + function createSessionBackup() { let sessionBackup = new backup.SessionBackup({ onFileReady: (err: BusinessError, file: backup.File) => { if (err) { - console.info('onFileReady err: ' + err); + console.info('onFileReady err: ' + JSON.stringify(err)); } try { let bundlePath = filesDir + '/' + file.bundleName; @@ -116,21 +126,21 @@ }, onBundleBegin: (err: BusinessError, bundleName: string) => { if (err) { - console.info('onBundleBegin err: ' + err); + console.info('onBundleBegin err: ' + JSON.stringify(err)); } else { console.info('onBundleBegin bundleName: ' + bundleName); } }, onBundleEnd: (err: BusinessError, bundleName: string) => { if (err) { - console.info('onBundleEnd err: ' + err); + console.info('onBundleEnd err: ' + JSON.stringify(err)); } else { console.info('onBundleEnd bundleName: ' + bundleName); } }, onAllBundlesEnd: (err: BusinessError) => { if (err) { - console.info('onAllBundlesEnd err: ' + err); + console.info('onAllBundlesEnd err: ' + JSON.stringify(err)); } else { console.info('onAllBundlesEnd'); } @@ -141,8 +151,8 @@ }); return sessionBackup; } - - async sessionBackup () { + + async function sessionBackup () { g_session = createSessionBackup(); // 此处可根据backup.getLocalCapabilities()提供的能力文件,选择需要备份的应用 // 也可直接根据应用包名称进行备份 @@ -165,20 +175,22 @@ **示例** ```ts + import backup from '@ohos.file.backup'; import fs from '@ohos.file.fs'; + import { BusinessError } from '@ohos.base'; // 创建SessionRestore类的实例用于恢复数据 let g_session: backup.SessionRestore; - async publishFile(file: backup.File) { + async function publishFile(file: backup.File) { await g_session.publishFile({ bundleName: file.bundleName, uri: file.uri }); } - createSessionRestore() { + function createSessionRestore() { let sessionRestore = new backup.SessionRestore({ onFileReady: (err: BusinessError, file: backup.File) => { if (err) { - console.info('onFileReady err: ' + err); + console.info('onFileReady err: ' + JSON.stringify(err)); } // 此处开发者请根据实际场景待恢复文件存放位置进行调整 bundlePath let bundlePath: string; @@ -193,19 +205,19 @@ }, onBundleBegin: (err: BusinessError, bundleName: string) => { if (err) { - console.error('onBundleBegin failed with err: ' + err); + console.error('onBundleBegin failed with err: ' + JSON.stringify(err)); } console.info('onBundleBegin success'); }, onBundleEnd: (err: BusinessError, bundleName: string) => { if (err) { - console.error('onBundleEnd failed with err: ' + err); + console.error('onBundleEnd failed with err: ' + JSON.stringify(err)); } console.info('onBundleEnd success'); }, onAllBundlesEnd: (err: BusinessError) => { if (err) { - console.error('onAllBundlesEnd failed with err: ' + err); + console.error('onAllBundlesEnd failed with err: ' + JSON.stringify(err)); } console.info('onAllBundlesEnd success'); }, @@ -215,16 +227,16 @@ }); return sessionRestore; } - - async restore01 () { + + async function restore01 () { g_session = createSessionRestore(); - const backupApps: string[] = [ + const restoreApps: string[] = [ "com.example.hiworld", ] // 能力文件的获取方式可以根据开发者实际场景进行调整。此处仅为请求示例 // 开发者也可以根据能力文件内容的结构示例,自行构造能力文件内容 let fileData = await backup.getLocalCapabilities(); - await g_session.appendBundles(fileData.fd, backupApps); + await g_session.appendBundles(fileData.fd, restoreApps); console.info('appendBundles success'); // 添加需要恢复的应用成功后,请根据需要恢复的应用名称,调用getFileHandle接口获取待恢复应用数文件的文件句柄 // 应用待恢复数据文件数请依据实际备份文件个数为准,此处仅为请求示例 @@ -251,21 +263,28 @@ **示例** ```ts + import backup from '@ohos.file.backup'; + import common from '@ohos.app.ability.common'; import fs from '@ohos.file.fs'; + import { BusinessError } from '@ohos.base'; + + // 获取沙箱路径 + let context = getContext(this) as common.UIAbilityContext; + let filesDir = context.filesDir; // 创建SessionRestore类的实例用于恢复数据 let g_session: backup.SessionRestore; - async publishFile(file) { + async function publishFile(file: backup.File) { await g_session.publishFile({ bundleName: file.bundleName, uri: file.uri }); } - createSessionRestore() { + function createSessionRestore() { let sessionRestore = new backup.SessionRestore({ onFileReady: (err: BusinessError, file: backup.File) => { - if (err) { - console.info('onFileReady err: ' + err); - } + if (err) { + console.info('onFileReady err: ' + JSON.stringify(err)); + } let bundlePath: string; if( file.uri == "/data/storage/el2/restore/bundle.hap" ) { @@ -284,19 +303,19 @@ }, onBundleBegin: (err: BusinessError, bundleName: string) => { if (err) { - console.error('onBundleBegin failed with err: ' + err); + console.error('onBundleBegin failed with err: ' + JSON.stringify(err)); } console.info('onBundleBegin success'); }, onBundleEnd: (err: BusinessError, bundleName: string) => { if (err) { - console.error('onBundleEnd failed with err: ' + err); + console.error('onBundleEnd failed with err: ' + JSON.stringify(err)); } console.info('onBundleEnd success'); }, onAllBundlesEnd: (err: BusinessError) => { if (err) { - console.error('onAllBundlesEnd failed with err: ' + err); + console.error('onAllBundlesEnd failed with err: ' + JSON.stringify(err)); } console.info('onAllBundlesEnd success'); }, @@ -306,28 +325,28 @@ }); return sessionRestore; } - - async restore02 () { + + async function restore02 () { g_session = createSessionRestore(); - const backupApps: string[] = [ + const restoreApps: string[] = [ "com.example.hiworld", ] - let fpath = await globalThis.context.filesDir + '/localCapabilities.json'; - let file = fs.openSync(fpath, fileIO.OpenMode.CREATE | fileIO.OpenMode.READ_WRITE); + let fpath = filesDir + '/localCapabilities.json'; + let file = fs.openSync(fpath, fs.OpenMode.CREATE | fs.OpenMode.READ_WRITE); let content = "{\"bundleInfos\" :[{\"allToBackup\" : false,\"extensionName\" : \"\"," + "\"name\" : \"cn.openharmony.inputmethodchoosedialog\",\"needToInstall\" : true,\"spaceOccupied\" : 0," + "\"versionCode\" : 1000000,\"versionName\" : \"1.0.0\"}],\"deviceType\" : \"default\",\"systemFullName\" : \"OpenHarmony-4.0.6.2(Canary1)\"}"; fs.writeSync(file.fd, content); fs.fsyncSync(file.fd); - await g_session.appendBundles(file.fd, backupApps); + await g_session.appendBundles(file.fd, restoreApps); console.info('appendBundles success'); - + // 开发者需要请求安装应用的文件句柄 await g_session.getFileHandle({ bundleName: restoreApps[0], uri: "/data/storage/el2/restore/bundle.hap" }); - + await g_session.getFileHandle({ bundleName: restoreApps[0], uri: "manage.json" diff --git a/zh-cn/application-dev/file-management/app-file-upload-download.md b/zh-cn/application-dev/file-management/app-file-upload-download.md index bde07c15debc054dcf3b70ea7307d28c9990d40b..de011ba94c049c4c98d3b8a90d9b2d19ca9aed5a 100644 --- a/zh-cn/application-dev/file-management/app-file-upload-download.md +++ b/zh-cn/application-dev/file-management/app-file-upload-download.md @@ -31,16 +31,19 @@ fs.writeSync(file.fd, 'upload file test'); fs.closeSync(file); // 上传任务配置项 +let header = new Map(); +header.set('key1', 'value1'); +header.set('key2', 'value2'); let files: Array = [ { filename: 'test.txt', name: 'test', uri: 'internal://cache/test.txt', type: 'txt' } ] -let data: request.RequestData = { name: 'name', value: 'value' }; +let data: Array = [{ name: 'name', value: 'value' }]; let uploadConfig: request.UploadConfig = { url: 'https://xxx', - header: { key1: 'value1', key2: 'value2' }, + header: header, method: 'POST', files: files, - data: [ data ] + data: data } // 将本地应用文件上传至网络服务器 @@ -56,7 +59,8 @@ try { .catch((err: BusinessError) => { console.error(`Invoke uploadFile failed, code is ${err.code}, message is ${err.message}`); }) -} catch (err) { +} catch (error) { + let err: BusinessError = error as BusinessError; console.error(`Invoke uploadFile failed, code is ${err.code}, message is ${err.message}`); } ``` @@ -80,6 +84,7 @@ import common from '@ohos.app.ability.common'; import fs from '@ohos.file.fs'; import request from '@ohos.request'; import { BusinessError } from '@ohos.base'; +import buffer from '@ohos.buffer'; // 获取应用文件路径 let context = getContext(this) as common.UIAbilityContext; @@ -102,7 +107,8 @@ try { }).catch((err: BusinessError) => { console.error(`Invoke downloadTask failed, code is ${err.code}, message is ${err.message}`); }); -} catch (err) { +} catch (error) { + let err: BusinessError = error as BusinessError; console.error(`Invoke downloadFile failed, code is ${err.code}, message is ${err.message}`); } ``` diff --git a/zh-cn/application-dev/file-management/dev-user-file-manager.md b/zh-cn/application-dev/file-management/dev-user-file-manager.md index 4ee4838b0fe7a136887d5ad926dc15cef127c4b9..0e6bea629835e3d9531663297e57250b2d0c27ce 100644 --- a/zh-cn/application-dev/file-management/dev-user-file-manager.md +++ b/zh-cn/application-dev/file-management/dev-user-file-manager.md @@ -23,6 +23,7 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以 import fileAccess from '@ohos.file.fileAccess'; import fileExtensionInfo from '@ohos.file.fileExtensionInfo'; import { Filter } from '@ohos.file.fs'; + import common from '@ohos.app.ability.common'; ``` 其中fileAccess提供了文件基础操作的API,fileExtensionInfo提供了应用开发的关键结构体。 @@ -33,11 +34,14 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以 在文件访问框架中,使用RootInfo用于表示设备的属性信息。以下示例可以获取所有设备的RootInfo。 ```ts + // 获取应用上下文 + let context = getContext(this) as common.UIAbilityContext; + // 创建连接系统内所有文件管理服务端的helper对象 let fileAccessHelperAllServer: fileAccess.FileAccessHelper; - createFileAccessHelper() { + function createFileAccessHelper() { try { // this.context是EntryAbility传过来的Context - fileAccessHelperAllServer = fileAccess.createFileAccessHelper(this.context); + fileAccessHelperAllServer = fileAccess.createFileAccessHelper(context); if (!fileAccessHelperAllServer) { console.error("createFileAccessHelper interface returns an undefined object"); } @@ -45,7 +49,7 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以 console.error("createFileAccessHelper failed, errCode:" + error.code + ", errMessage:" + error.message); } } - async getRoots() { + async function getRoots() { let rootIterator: fileAccess.RootIterator; let rootInfos: fileAccess.RootInfo[] = []; let isDone: boolean = false; @@ -62,7 +66,8 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以 if (!isDone) rootInfos.push(result.value); } - } catch (error) { + } catch (err) { + let error: BusinessError = err as BusinessError; console.error("getRoots failed, errCode:" + error.code + ", errMessage:" + error.message); } } @@ -93,7 +98,8 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以 if (!isDone) fileInfos.push(result.value); } - } catch (error) { + } catch (err) { + let error: BusinessError = err as BusinessError; console.error("listFile failed, errCode:" + error.code + ", errMessage:" + error.message); } @@ -116,7 +122,8 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以 if (!isDone) subFileInfos.push(result.value); } - } catch (error) { + } catch (err) { + let error: BusinessError = err as BusinessError; console.error("listFile failed, errCode:" + error.code + ", errMessage:" + error.message); } ``` @@ -140,7 +147,8 @@ OpenHarmony预置了FileManager文件管理器。系统应用开发者也可以 return; } console.info("createFile sucess, fileUri: " + JSON.stringify(fileUri)); - } catch (error) { + } catch (err) { + let error: BusinessError = err as BusinessError; console.error("createFile failed, errCode:" + error.code + ", errMessage:" + error.message); }; ``` diff --git a/zh-cn/application-dev/file-management/file-access-across-devices.md b/zh-cn/application-dev/file-management/file-access-across-devices.md index b113f565d4c7aa881dccec74c11185d9ae69a551..a2e003d977bc815847c39edeb757a221b193a849 100644 --- a/zh-cn/application-dev/file-management/file-access-across-devices.md +++ b/zh-cn/application-dev/file-management/file-access-across-devices.md @@ -29,7 +29,8 @@ fs.writeSync(file.fd, 'content'); // 关闭文件 fs.closeSync(file.fd); - } catch (err) { + } catch (error) { + let err: BusinessError = error as BusinessError; console.error(`Failed to openSync / writeSync / closeSync. Code: ${err.code}, message: ${err.message}`); } ``` @@ -58,7 +59,8 @@ // 打印读取到的文件数据 let buf = buffer.from(arrayBuffer, 0, num); console.info('read result: ' + buf.toString()); - } catch (err) { + } catch (error) { + let err: BusinessError = error as BusinessError; console.error(`Failed to openSync / readSync. Code: ${err.code}, message: ${err.message}`); } ``` diff --git a/zh-cn/application-dev/file-management/manage-external-storage.md b/zh-cn/application-dev/file-management/manage-external-storage.md index 8ed79dbc3678d448b5614aea9d0280fd42f9c241..e71888cf9aeaeee7f19f9d272e4448c14ea0ad5d 100644 --- a/zh-cn/application-dev/file-management/manage-external-storage.md +++ b/zh-cn/application-dev/file-management/manage-external-storage.md @@ -78,7 +78,7 @@ let volId: string = data.parameters.id; volumeManager.getVolumeById(volId, (error: BusinessError, vol: volumeManager.Volume) => { if (error) { - console.error('volumeManager getVolumeById failed'); + console.error('volumeManager getVolumeById failed for ' + JSON.stringify(error)); } else { console.info('volumeManager getVolumeById successfully, the volume state is ' + vol.state); } diff --git a/zh-cn/application-dev/file-management/save-user-file.md b/zh-cn/application-dev/file-management/save-user-file.md index 15121f354a20290e5f08e1ac72ba7bfae1ff0c56..da1d42019d301c462469ee4f302841dcb4fc7c7a 100644 --- a/zh-cn/application-dev/file-management/save-user-file.md +++ b/zh-cn/application-dev/file-management/save-user-file.md @@ -30,7 +30,7 @@ save接口会将文件保存在文件管理器,而不是图库。 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let pixelmapArrayBuffer: ArrayBuffer; - async getPixelmap() { + async function getPixelmap() { try { let predicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { @@ -48,10 +48,11 @@ save接口会将文件保存在文件管理器,而不是图库。 pixelmapArrayBuffer = readBuffer; }) }).catch((err: BusinessError) => { - console.error('[picker] getThumbnail failed with error: ' + err); + console.error('[picker] getThumbnail failed with error: ' + JSON.stringify(err)); }); } catch (error) { - console.error('[picker] getThumbnail error = ' + error); + let err: BusinessError = error as BusinessError; + console.error('[picker] getThumbnail error = ' + JSON.stringify(err)); } } ``` @@ -74,11 +75,13 @@ save接口会将文件保存在文件管理器,而不是图库。 uris = photoSaveResult; console.info('photoViewPicker.save to file succeed and uris are:' + uris); } - } catch (err) { + } catch (error) { + let err: BusinessError = error as BusinessError; console.error(`[picker] Invoke photoViewPicker.save failed, code is ${err.code}, message is ${err.message}`); } } catch (error) { - console.info("[picker] photoViewPickerSave error = " + error); + let err: BusinessError = error as BusinessError; + console.info("[picker] photoViewPickerSave error = " + JSON.stringify(err)); } } ``` @@ -88,14 +91,15 @@ save接口会将文件保存在文件管理器,而不是图库。 然后,通过fd使用[fs.write](../reference/apis/js-apis-file-fs.md#fswrite)接口对这个文件进行编辑修改,编辑修改完成后关闭fd。 ```ts - async writeOnly(uri: string) { + async function writeOnly(uri: string) { try { let file = fs.openSync(uri, fs.OpenMode.WRITE_ONLY); let writeLen = await fs.write(file.fd, pixelmapArrayBuffer); fs.closeSync(file); console.info("[picker] writeOnly writeLen = " + writeLen); } catch (error) { - console.info("[picker] writeOnly error: " + error); + let err: BusinessError = error as BusinessError; + console.info("[picker] writeOnly error: " + JSON.stringify(err)); } } ``` diff --git a/zh-cn/application-dev/file-management/select-user-file.md b/zh-cn/application-dev/file-management/select-user-file.md index 1bd67b591f9209176452b2ef484d517f90a49acd..40ab0a19a3b519cda20da841b4c0a733a34aeccf 100644 --- a/zh-cn/application-dev/file-management/select-user-file.md +++ b/zh-cn/application-dev/file-management/select-user-file.md @@ -124,6 +124,7 @@ // 获取到文档文件的文件名称 let file_name_list = result.want.parameters.file_name_list; } catch (err) { + let err: BusinessError = error as BusinessError; console.error(`Invoke documentViewPicker.select failed, code is ${err.code}, message is ${err.message}`); } ``` diff --git a/zh-cn/application-dev/file-management/share-app-file.md b/zh-cn/application-dev/file-management/share-app-file.md index 9186dcad5112cc97bafec468a27a27d064a0a796..bdcf245eaab81ba18890d8246b419c65dc005d41 100644 --- a/zh-cn/application-dev/file-management/share-app-file.md +++ b/zh-cn/application-dev/file-management/share-app-file.md @@ -138,11 +138,13 @@ function getShareFile() { // 根据需要对被分享文件的URI进行相应操作。例如读写的方式打开URI获取file对象 let file = fs.openSync(uri, fs.OpenMode.READ_WRITE); console.info('open file successfully!'); - } catch (error) { + } catch (err) { + let error: BusinessError = err as BusinessError; console.error(`Invoke openSync failed, code is ${error.code}, message is ${error.message}`); } } catch (error) { - console.error(`Invoke openSync failed, code is ${error.code}, message is ${error.message}`); + let err: BusinessError = error as BusinessError; + console.error(`Invoke openSync failed, code is ${err.code}, message is ${err.message}`); } } ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-picker.md b/zh-cn/application-dev/reference/apis/js-apis-file-picker.md index b6c2930769df92244dab08026772a7a95166d561..fcb1600558297074bc27f5665ed0fcf2531417b4 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-picker.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-picker.md @@ -52,7 +52,7 @@ select(option?: PhotoSelectOptions) : Promise<PhotoSelectResult> **示例:** ```ts -async example01() { +async function example01() { try { let PhotoSelectOptions = new picker.PhotoSelectOptions(); PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; @@ -61,10 +61,11 @@ async example01() { photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: picker.PhotoSelectResult) => { console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); }).catch((err: BusinessError) => { - console.error('PhotoViewPicker.select failed with err: ' + err); + console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); }); - } catch (err) { - console.error('PhotoViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('PhotoViewPicker failed with err: ' + + JSON.stringify(err)); } } ``` @@ -87,7 +88,7 @@ select(option: PhotoSelectOptions, callback: AsyncCallback<PhotoSelectResult& **示例:** ```ts -async example02() { +async function example02() { try { let PhotoSelectOptions = new picker.PhotoSelectOptions(); PhotoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE; @@ -95,13 +96,14 @@ async example02() { let photoPicker = new picker.PhotoViewPicker(); photoPicker.select(PhotoSelectOptions, (err: BusinessError, PhotoSelectResult: picker.PhotoSelectResult) => { if (err) { - console.error('PhotoViewPicker.select failed with err: ' + err); + console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); return; } console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); }); - } catch (err) { - console.error('PhotoViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -123,18 +125,19 @@ select(callback: AsyncCallback<PhotoSelectResult>) : void **示例:** ```ts -async example03() { +async function example03() { try { let photoPicker = new picker.PhotoViewPicker(); photoPicker.select((err: BusinessError, PhotoSelectResult: picker.PhotoSelectResult) => { if (err) { - console.error('PhotoViewPicker.select failed with err: ' + err); + console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(err)); return; } console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); }); - } catch (err) { - console.error('PhotoViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -162,7 +165,7 @@ save(option?: PhotoSaveOptions) : Promise<Array<string>> **示例:** ```ts -async example04() { +async function example04() { try { let PhotoSaveOptions = new picker.PhotoSaveOptions(); PhotoSaveOptions.newFileNames = ['PhotoViewPicker01.jpg', 'PhotoViewPicker01.mp4']; @@ -170,10 +173,11 @@ async example04() { photoPicker.save(PhotoSaveOptions).then((PhotoSaveResult: Array) => { console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult)); }).catch((err: BusinessError) => { - console.error('PhotoViewPicker.save failed with err: ' + err); + console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err)); }); - } catch (err) { - console.error('PhotoViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -196,20 +200,21 @@ save(option: PhotoSaveOptions, callback: AsyncCallback<Array<string>> **示例:** ```ts -async example05() { +async function example05() { try { let PhotoSaveOptions = new picker.PhotoSaveOptions(); PhotoSaveOptions.newFileNames = ['PhotoViewPicker02.jpg','PhotoViewPicker02.mp4']; let photoPicker = new picker.PhotoViewPicker(); photoPicker.save(PhotoSaveOptions, (err: BusinessError, PhotoSaveResult: Array) => { if (err) { - console.error('PhotoViewPicker.save failed with err: ' + err); + console.error('PhotoViewPicker.save failed with err: ' JSON.stringify(err)); return; } console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult)); }); - } catch (err) { - console.error('PhotoViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -231,18 +236,19 @@ save(callback: AsyncCallback<Array<string>>) : void **示例:** ```ts -async example06() { +async function example06() { try { let photoPicker = new picker.PhotoViewPicker(); photoPicker.save((err: BusinessError, PhotoSaveResult: Array) => { if (err) { - console.error('PhotoViewPicker.save failed with err: ' + err); + console.error('PhotoViewPicker.save failed with err: ' + JSON.stringify(err)); return; } console.info('PhotoViewPicker.save successfully, PhotoSaveResult uri: ' + JSON.stringify(PhotoSaveResult)); }); - } catch (err) { - console.error('PhotoViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('PhotoViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -282,17 +288,18 @@ select(option?: DocumentSelectOptions) : Promise<Array<string>> **示例:** ```ts -async example07() { +async function example07() { try { let DocumentSelectOptions = new picker.DocumentSelectOptions(); let documentPicker = new picker.DocumentViewPicker(); documentPicker.select(DocumentSelectOptions).then((DocumentSelectResult: Array) => { console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult)); }).catch((err: BusinessError) => { - console.error('DocumentViewPicker.select failed with err: ' + err); + console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err)); }); - } catch (err) { - console.error('DocumentViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -315,19 +322,20 @@ select(option: DocumentSelectOptions, callback: AsyncCallback<Array<string **示例:** ```ts -async example08() { +async function example08() { try { let DocumentSelectOptions = new picker.DocumentSelectOptions(); let documentPicker = new picker.DocumentViewPicker(); documentPicker.select(DocumentSelectOptions, (err: BusinessError, DocumentSelectResult: Array) => { if (err) { - console.error('DocumentViewPicker.select failed with err: ' + err); + console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err)); return; } console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult)); }); - } catch (err) { - console.error('DocumentViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -349,18 +357,19 @@ select(callback: AsyncCallback<Array<string>>) : void **示例:** ```ts -async example09() { +async function example09() { try { let documentPicker = new picker.DocumentViewPicker(); documentPicker.select((err: BusinessError, DocumentSelectResult: Array) => { if (err) { - console.error('DocumentViewPicker.select failed with err: ' + err); + console.error('DocumentViewPicker.select failed with err: ' + JSON.stringify(err)); return; } console.info('DocumentViewPicker.select successfully, DocumentSelectResult uri: ' + JSON.stringify(DocumentSelectResult)); }); - } catch (err) { - console.error('DocumentViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -389,7 +398,7 @@ save(option?: DocumentSaveOptions) : Promise<Array<string>> **示例:** ```ts -async example10() { +async function example10() { try { let DocumentSaveOptions = new picker.DocumentSaveOptions(); DocumentSaveOptions.newFileNames = ['DocumentViewPicker01.txt']; @@ -397,10 +406,11 @@ async example10() { documentPicker.save(DocumentSaveOptions).then((DocumentSaveResult: Array) => { console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult)); }).catch((err: BusinessError) => { - console.error('DocumentViewPicker.save failed with err: ' + err); + console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err)); }); - } catch (err) { - console.error('DocumentViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -423,20 +433,21 @@ save(option: DocumentSaveOptions, callback: AsyncCallback<Array<string> **示例:** ```ts -async example11() { +async function example11() { try { let DocumentSaveOptions = new picker.DocumentSaveOptions(); DocumentSaveOptions.newFileNames = ['DocumentViewPicker02.txt']; let documentPicker = new picker.DocumentViewPicker(); documentPicker.save(DocumentSaveOptions, (err: BusinessError, DocumentSaveResult: Array) => { if (err) { - console.error('DocumentViewPicker.save failed with err: ' + err); + console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err)); return; } console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult)); }); - } catch (err) { - console.error('DocumentViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -458,18 +469,19 @@ save(callback: AsyncCallback<Array<string>>) : void **示例:** ```ts -async example12() { +async function example12() { try { let documentPicker = new picker.DocumentViewPicker(); documentPicker.save((err: BusinessError, DocumentSaveResult: Array) => { if (err) { - console.error('DocumentViewPicker.save failed with err: ' + err); + console.error('DocumentViewPicker.save failed with err: ' + JSON.stringify(err)); return; } console.info('DocumentViewPicker.save successfully, DocumentSaveResult uri: ' + JSON.stringify(DocumentSaveResult)); }); - } catch (err) { - console.error('DocumentViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('DocumentViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -509,17 +521,18 @@ select(option?: AudioSelectOptions) : Promise<Array<string>> **示例:** ```ts -async example13() { +async function example13() { try { let AudioSelectOptions = new picker.AudioSelectOptions(); let audioPicker = new picker.AudioViewPicker(); audioPicker.select(AudioSelectOptions).then((AudioSelectResult: Array) => { console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult)); }).catch((err: BusinessError) => { - console.error('AudioViewPicker.select failed with err: ' + err); + console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err)); }); - } catch (err) { - console.error('AudioViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -542,19 +555,20 @@ select(option: AudioSelectOptions, callback: AsyncCallback<Array<string> **示例:** ```ts -async example14() { +async function example14() { try { let AudioSelectOptions = new picker.AudioSelectOptions(); let audioPicker = new picker.AudioViewPicker(); audioPicker.select(AudioSelectOptions, (err: BusinessError, AudioSelectResult: Array) => { if (err) { - console.error('AudioViewPicker.select failed with err: ' + err); + console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err)); return; } console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult)); }); - } catch (err) { - console.error('AudioViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -576,18 +590,19 @@ select(callback: AsyncCallback<Array<string>>) : void **示例:** ```ts -async example15() { +async function example15() { try { let audioPicker = new picker.AudioViewPicker(); audioPicker.select((err: BusinessError, AudioSelectResult: Array) => { if (err) { - console.error('AudioViewPicker.select failed with err: ' + err); + console.error('AudioViewPicker.select failed with err: ' + JSON.stringify(err)); return; } console.info('AudioViewPicker.select successfully, AudioSelectResult uri: ' + JSON.stringify(AudioSelectResult)); }); - } catch (err) { - console.error('AudioViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -615,7 +630,7 @@ save(option?: AudioSaveOptions) : Promise<Array<string>> **示例:** ```ts -async example16() { +async function example16() { try { let AudioSaveOptions = new picker.AudioSaveOptions(); AudioSaveOptions.newFileNames = ['AudioViewPicker01.mp3']; @@ -623,10 +638,11 @@ async example16() { audioPicker.save(AudioSaveOptions).then((AudioSaveResult: Array) => { console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult)) }).catch((err: BusinessError) => { - console.error('AudioViewPicker.save failed with err: ' + err); + console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err)); }); - } catch (err) { - console.error('AudioViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -649,20 +665,21 @@ save(option: AudioSaveOptions, callback: AsyncCallback<Array<string>> **示例:** ```ts -async example17() { +async function example17() { try { let AudioSaveOptions = new picker.AudioSaveOptions(); AudioSaveOptions.newFileNames = ['AudioViewPicker02.mp3']; let audioPicker = new picker.AudioViewPicker(); audioPicker.save(AudioSaveOptions, (err: BusinessError, AudioSaveResult: Array) => { if (err) { - console.error('AudioViewPicker.save failed with err: ' + err); + console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err)); return; } console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult)); }); - } catch (err) { - console.error('AudioViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); } } ``` @@ -684,18 +701,19 @@ save(callback: AsyncCallback<Array<string>>) : void **示例:** ```ts -async example18() { +async function example18() { try { let audioPicker = new picker.AudioViewPicker(); audioPicker.save((err: BusinessError, AudioSaveResult: Array) => { if (err) { - console.error('AudioViewPicker.save failed with err: ' + err); + console.error('AudioViewPicker.save failed with err: ' + JSON.stringify(err)); return; } console.info('AudioViewPicker.save successfully, AudioSaveResult uri: ' + JSON.stringify(AudioSaveResult)); }); - } catch (err) { - console.error('AudioViewPicker failed with err: ' + err); + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('AudioViewPicker failed with err: ' + JSON.stringify(err)); } } ```