From 1226f3ce1b7de1855e287af55d7e325eb39d7ea4 Mon Sep 17 00:00:00 2001 From: liusaimei Date: Fri, 7 Jul 2023 14:58:54 +0800 Subject: [PATCH] modify datashare Signed-off-by: liusaimei --- .../reference/apis/js-apis-data-dataShare.md | 2 +- .../changelogs-datashare.md | 98 +------------------ 2 files changed, 2 insertions(+), 98 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md b/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md index 9c065da8f1..b83b3f3cb3 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md +++ b/zh-cn/application-dev/reference/apis/js-apis-data-dataShare.md @@ -199,7 +199,7 @@ try { | 名称 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | key | string | 是 | 指定发布数据的键。 | -| data | string \| ArrayBuffer | 是 | 指定发布的数据。如果数据很大,请使用ArrayBuffer。 | +| data | string \| ArrayBuffer | 是 | 指定发布的数据。如果数据很大,请使用ArrayBuffer,建议20KB及以上使用ArrayBuffer。 | | subscriberId | string | 是 | 指定订阅者id。 | ## RdbDataChangeNode10+ diff --git a/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md b/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md index 87e7314bf1..8297f9f766 100644 --- a/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md +++ b/zh-cn/release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-datashare.md @@ -21,115 +21,19 @@ **适配指导** 示例代码如下: -变更前代码示例: - -**示例** - -```ts -import rpc from '@ohos.rpc'; - -function onPublishCallback(err, node:dataShare.PublishedDataChangeNode) { - console.info("onPublishCallback node bundleName " + JSON.stringify(node.bundleName)); - console.info("onPublishCallback node data size" + node.data.length); - for (let i = 0; i < node.data.length; i++) { - console.info("onPublishCallback node " + typeof node.data[i].data); - if (typeof node.data[i].data != 'string') { - let ash:rpc.Ashmem = node.data[i].data; - ash.mapReadonlyAshmem(); - console.info("onPublishCallback " + JSON.stringify(ash.readAshmem(ash.getAshmemSize()/4, 0))); - ash.closeAshmem(); - } - console.info("onPublishCallback data " + i + " " + JSON.stringify(node.data[i])); - } -} -let uris:Array = ['city', 'datashareproxy://com.acts.ohos.data.datasharetest/appInfo', 'key2']; -let subscriberId = '11'; -let result: Array = dataShareHelper.on('publishedDataChange', uris, subscriberId, onPublishCallback); -``` - -**示例** - -```ts -import rpc from '@ohos.rpc'; - -let ashmem = null; -let subscriberId = '11'; -let version = 1; -let data : Array = [ - {key:"city", subscriberId:"11", data:"xian"}, - {key:"datashareproxy://com.acts.ohos.data.datasharetest/appInfo", subscriberId:"11", data:"appinfo is just a test app"}, - {key:"empty", subscriberId:"11", data:"nobody sub"}]; -let nums:number[] = [1,2,3]; -function publishCallback(err, result: Array) { - console.info("publishCallback " + JSON.stringify(result)); - ashmem.closeAshmem(); -} -try { - ashmem = rpc.Ashmem.create("ashmem", (nums.length) * 4); - ashmem.mapReadWriteAshmem(); - ashmem.writeAshmem(nums, nums.length, 0); - data.push({ - "key" : "key2", - "data" : ashmem, - "subscriberId" : "11", - }); - console.info("data length is:", data.length); - dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback); -} catch (e) { - console.error("publish error " + JSON.stringify(e)); -} -``` - -变更后代码示例: - **示例:** ```ts -import rpc from '@ohos.rpc'; - function onPublishCallback(err, node:dataShare.PublishedDataChangeNode) { - console.info("onPublishCallback node bundleName " + JSON.stringify(node.bundleName)); - console.info("onPublishCallback node data size" + node.data.length); for (let i = 0; i < node.data.length; i++) { - console.info("onPublishCallback node " + typeof node.data[i].data); if (typeof node.data[i].data != 'string') { let array:ArrayBuffer = node.data[i].data; let data:Uint8Array = new Uint8Array(array); - console.info("onPublishCallback " + i + " " + JSON.stringify(data)); + console.info("onPublishCallback " + JSON.stringify(data)); } - console.info("onPublishCallback data " + i + " " + JSON.stringify(node.data[i])); } } let uris:Array = ['city', 'datashareproxy://com.acts.ohos.data.datasharetest/appInfo', 'key2']; let subscriberId = '11'; let result: Array = dataShareHelper.on('publishedDataChange', uris, subscriberId, onPublishCallback); -``` - -**示例:** - -```ts -let arrayBuffer = null; -let subscriberId = '11'; -let version = 1; -let data : Array = [ - {key:"city", subscriberId:"11", data:"xian"}, - {key:"datashareproxy://com.acts.ohos.data.datasharetest/appInfo", subscriberId:"11", data:"appinfo is just a test app"}, - {key:"empty", subscriberId:"11", data:"nobody sub"}]; -let nums:number[] = [1,2,3]; -function publishCallback(err, result: Array) { - console.info("publishCallback " + JSON.stringify(result)); -} -try { - arrayBuffer = new ArrayBuffer(nums.length); - let array:Uint8Array = new Uint8Array(arrayBuffer); - data.push({ - "key" : "key2", - "data" : array, - "subscriberId" : "11", - }); - console.info("data length is:", data.length); - dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback); -} catch (e) { - console.error("publish error " + JSON.stringify(e)); -} ``` \ No newline at end of file -- GitLab