# 资源管理changeLog ## cl.resourceManager.1 资源API9部分多工程接口命名变更 资源管理从API9开始提供接口的错误码和错误信息返回,涉及API9提供的部分多工程接口需要适配。从API9开始作以下变更: 资源API部分多工程接口需要用新的接口替换,参数不变。 **变更影响** 基于此前版本开发的应用,涉及下面多工程接口的JS接口需要替换为新的接口。 **关键接口/组件变更** | **涉及接口** | **对应替换接口** | | ---------------- | ------------ | | getString(resource: Resource,
callback: AsyncCallback\): void; | getStringValue(resource: Resource,
callback: AsyncCallback\): void; | | getString(resource: Resource): Promise\; | getStringValue(resource: Resource): Promise\; | | getStringArray(resource: Resource,
callback: AsyncCallback\>): void; | getStringArrayValue(resource: Resource,
callback: AsyncCallback\>): void; | | getStringArray(resource: Resource): Promise\>; | getStringArrayValue(resource: Resource): Promise\>; | | getMedia(resource: Resource,
callback: AsyncCallback\): void; | getMediaContent(resource: Resource,
callback: AsyncCallback\): void; | | getMedia(resource: Resource): Promise\; | getMediaContent(resource: Resource): Promise\; | | getMediaBase64(resource: Resource,
callback: AsyncCallback\): void; | getMediaContentBase64(resource: Resource,
callback: AsyncCallback\): void; | | getMediaBase64(resource: Resource): Promise\; | getMediaContentBase64(resource: Resource): Promise\; | | getPluralString(resource: Resource, num: number,
callback: AsyncCallback): void; | getPluralStringValue(resource: Resource, num: number,
callback: AsyncCallback\): void; | | getPluralString(resource: Resource, num: number): Promise\; | getPluralStringValue(resource: Resource, num: number): Promise\; | **适配指导** 以getMedia修改为getMediaContent的callback调用为例,其promise方式类似,只需修改函数名,且增加错误码和错误信息返回,其它不变。示例代码如下: - 变更前:getMedia(resource: Resource, callback: AsyncCallback): void; ```ts let resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; this.context.resourceManager.getMedia(resource, (error, value) => { if (error != null) { console.log("error is " + error); } else { let media = value; } }); ``` - 变更后:getMediaContent(resource: Resource, callback: AsyncCallback): void; ```ts let resource = { bundleName: "com.example.myapplication", moduleName: "entry", id: $r('app.media.test').id }; try { this.context.resourceManager.getMediaContent(resource, (error, value) => { if (error != null) { console.log("error is " + error); } else { let media = value; } }); } catch (error) { console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`) } ```