提交 956156b3 编写于 作者: L liusaimei

modify datashare

Signed-off-by: Nliusaimei <lirui.wx1229126@huawei.com>
上级 1a5b5140
...@@ -558,25 +558,13 @@ publish(data: Array&lt;PublishedItem&gt;, bundleName: string, version: number, c ...@@ -558,25 +558,13 @@ publish(data: Array&lt;PublishedItem&gt;, bundleName: string, version: number, c
**示例:** **示例:**
```ts ```ts
let arrayBuffer = null; let arrayBuffer = new ArrayBuffer(1);
let subscriberId = '11';
let version = 1; let version = 1;
let data : Array<dataShare.PublishedItem> = [ let data : Array<dataShare.PublishedItem> = [{key:"key2", subscriberId:"11", data:arrayBuffer}];
{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<dataShare.OperationResult>) { function publishCallback(err, result: Array<dataShare.OperationResult>) {
console.info("publishCallback " + JSON.stringify(result)); console.info("publishCallback " + JSON.stringify(result));
} }
try { 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); console.info("data length is:", data.length);
dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback); dataShareHelper.publish(data, "com.acts.ohos.data.datasharetest", version, publishCallback);
} catch (e) { } catch (e) {
......
...@@ -24,16 +24,16 @@ PublishedItem中data的数据类型从Ashmem变更为ArrayBuffer ...@@ -24,16 +24,16 @@ PublishedItem中data的数据类型从Ashmem变更为ArrayBuffer
**示例:** **示例:**
```ts ```ts
function onPublishCallback(err, node:dataShare.PublishedDataChangeNode) { let arrayBuffer = new ArrayBuffer(1);
for (let i = 0; i < node.data.length; i++) { let version = 1;
if (typeof node.data[i].data != 'string') { let data : Array<dataShare.PublishedItem> = [{key:"key2", subscriberId:"11", data:arrayBuffer}];
let array:ArrayBuffer = node.data[i].data; function publishCallback(err, result: Array<dataShare.OperationResult>) {
let data:Uint8Array = new Uint8Array(array); console.info("publishCallback " + JSON.stringify(result));
console.info("onPublishCallback " + JSON.stringify(data)); }
} try {
} 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));
} }
let uris:Array<string> = ['city', 'datashareproxy://com.acts.ohos.data.datasharetest/appInfo', 'key2'];
let subscriberId = '11';
let result: Array<dataShare.OperationResult> = dataShareHelper.on('publishedDataChange', uris, subscriberId, onPublishCallback);
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册