1# 资源管理changeLog 2 3## cl.resourceManager.1 资源API9部分多工程接口命名变更 4 5资源管理从API9开始提供接口的错误码和错误信息返回,涉及API9提供的部分多工程接口需要适配。从API9开始作以下变更: 6 7资源API部分多工程接口需要用新的接口替换,参数不变。 8 9**变更影响** 10 11基于此前版本开发的应用,涉及下面多工程接口的JS接口需要替换为新的接口。 12 13**关键接口/组件变更** 14 15| **涉及接口** | **对应替换接口** | 16| ---------------- | ------------ | 17| getString(resource: Resource, </br>callback: AsyncCallback\<string>): void; | getStringValue(resource: Resource, </br>callback: AsyncCallback\<string>): void; | 18| getString(resource: Resource): Promise\<string>; | getStringValue(resource: Resource): Promise\<string>; | 19| getStringArray(resource: Resource, </br>callback: AsyncCallback\<Array\<string>>): void; | getStringArrayValue(resource: Resource, </br>callback: AsyncCallback\<Array\<string>>): void; | 20| getStringArray(resource: Resource): Promise\<Array\<string>>; | getStringArrayValue(resource: Resource): Promise\<Array\<string>>; | 21| getMedia(resource: Resource, </br>callback: AsyncCallback\<Uint8Array>): void; | getMediaContent(resource: Resource, </br>callback: AsyncCallback\<Uint8Array>): void; | 22| getMedia(resource: Resource): Promise\<Uint8Array>; | getMediaContent(resource: Resource): Promise\<Uint8Array>; | 23| getMediaBase64(resource: Resource, </br>callback: AsyncCallback\<string>): void; | getMediaContentBase64(resource: Resource, </br>callback: AsyncCallback\<string>): void; | 24| getMediaBase64(resource: Resource): Promise\<string>; | getMediaContentBase64(resource: Resource): Promise\<string>; | 25| getPluralString(resource: Resource, num: number, </br>callback: AsyncCallback<string>): void; | getPluralStringValue(resource: Resource, num: number, </br>callback: AsyncCallback\<string>): void; | 26| getPluralString(resource: Resource, num: number): Promise\<string>; | getPluralStringValue(resource: Resource, num: number): Promise\<string>; | 27 28**适配指导** 29 30以getMedia修改为getMediaContent的callback调用为例,其promise方式类似,只需修改函数名,且增加错误码和错误信息返回,其它不变。示例代码如下: 31 32- 变更前:getMedia(resource: Resource, callback: AsyncCallback<Uint8Array>): void; 33```ts 34let resource = { 35 bundleName: "com.example.myapplication", 36 moduleName: "entry", 37 id: $r('app.media.test').id 38}; 39this.context.resourceManager.getMedia(resource, (error, value) => { 40 if (error != null) { 41 console.log("error is " + error); 42 } else { 43 let media = value; 44 } 45}); 46``` 47 48- 变更后:getMediaContent(resource: Resource, callback: AsyncCallback<Uint8Array>): void; 49```ts 50let resource = { 51 bundleName: "com.example.myapplication", 52 moduleName: "entry", 53 id: $r('app.media.test').id 54}; 55try { 56 this.context.resourceManager.getMediaContent(resource, (error, value) => { 57 if (error != null) { 58 console.log("error is " + error); 59 } else { 60 let media = value; 61 } 62 }); 63} catch (error) { 64 console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`) 65} 66``` 67