1e41f4b71Sopenharmony_ci# @ohos.data.cloudExtension (端云共享Extension)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci端云共享Extension,提供三方厂商适配共享云服务的能力。通过实现端云共享Extension提供的接口,对接端侧的数据共享到服务端,实现端云共享的发起、取消或退出,更改共享数据的操作权限、查询共享参与者、根据共享邀请码查询共享参与者、确认或更改共享邀请,并支持返回共享云服务的相关结果。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci其中,端云共享资源标识是指:对于应用发起共享的每一条数据记录,该条数据在进行端云同步时会生成唯一的共享资源标识(字符串类型的值),此标识则作为该条数据记录共享时的识别标识。 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci端云共享参与者是指: 共享发起者根据好友列表选中的参与当前数据共享的所有人员。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci端云共享邀请码是指: 共享发起后,在共享的服务端会生成当前共享操作的邀请码,并将该邀请码附加到当前共享邀请中,通过push消息推送到被邀请者的设备端,被邀请者可以通过该邀请码进行邀请的确认。 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci同步云是指: 端云同步的服务端,是同应用同账号跨设备的同步。 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci共享云是指: 端云共享的服务端,是同应用跨账号跨设备的共享。 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci> **说明:** 16e41f4b71Sopenharmony_ci> 17e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 11开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 18e41f4b71Sopenharmony_ci> 19e41f4b71Sopenharmony_ci> - 本模块接口为系统接口。 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci## 导入模块 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci```ts 24e41f4b71Sopenharmony_ciimport { cloudExtension } from '@kit.ArkData'; 25e41f4b71Sopenharmony_ci``` 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci## Result<T> 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci共享结果的返回值。 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 34e41f4b71Sopenharmony_ci| ----------- | --------------------------- | --- | ------------ | 35e41f4b71Sopenharmony_ci| code | number | 是 | 错误码。 | 36e41f4b71Sopenharmony_ci| description | string | 否 | 错误码详细描述,默认为undefined。 | 37e41f4b71Sopenharmony_ci| value | T | 否 | 返回结果的值,具体类型由参数T指定,默认为undefined。 | 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci## CloudAsset 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci云资产的信息。 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 46e41f4b71Sopenharmony_ci| ------- | ------ | ---- | ------------------------------------ | 47e41f4b71Sopenharmony_ci| assetId | string | 是 | 资产ID。 | 48e41f4b71Sopenharmony_ci| hash | string | 是 | 资产的修改时间和大小转化成的哈希值。 | 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci## CloudAssets 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci表示[CloudAsset](#cloudasset)类型的数组。 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci| 类型 | 说明 | 57e41f4b71Sopenharmony_ci| -------------------------------- | ----------------------------------------- | 58e41f4b71Sopenharmony_ci| Array<[CloudAsset](#cloudasset)> | 表示[CloudAsset](#cloudasset)类型的数组。 | 59e41f4b71Sopenharmony_ci 60e41f4b71Sopenharmony_ci## ServiceInfo 61e41f4b71Sopenharmony_ci 62e41f4b71Sopenharmony_ci云服务信息。 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 65e41f4b71Sopenharmony_ci 66e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 67e41f4b71Sopenharmony_ci| -------------- | ------- | ---- | ------------------------------------------------------------ | 68e41f4b71Sopenharmony_ci| enableCloud | boolean | 是 | 表示是否启用了云服务,为true时是启用云服务,为false时是未启用。 | 69e41f4b71Sopenharmony_ci| id | string | 是 | 使用哈希函数SHA256生成的云账号ID。 | 70e41f4b71Sopenharmony_ci| totalSpace | number | 是 | 服务器上账号的总空间(KB)。 | 71e41f4b71Sopenharmony_ci| remainingSpace | number | 是 | 服务器上账号的可用空间(KB)。 | 72e41f4b71Sopenharmony_ci| user | number | 是 | 设备的当前用户ID。 | 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci## Flag 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci描述数据库上执行操作的枚举。请使用枚举名而非枚举值。 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 81e41f4b71Sopenharmony_ci| ------ | ---- | ---------- | 82e41f4b71Sopenharmony_ci| INSERT | 0 | 插入操作。 | 83e41f4b71Sopenharmony_ci| UPDATE | 1 | 更新操作。 | 84e41f4b71Sopenharmony_ci| DELETE | 2 | 删除操作。 | 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci## ExtensionValue 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci当前数据记录的扩展信息。 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci| 名称 | 类型 | 只读 | 可选 | 说明 | 93e41f4b71Sopenharmony_ci| ---------- | --------------- | ---- | ---- | ------------------ | 94e41f4b71Sopenharmony_ci| id | string | 是 | 否 | 执行插入操作时生成。 | 95e41f4b71Sopenharmony_ci| createTime | number | 是 | 否 | 创建行数据的时间。 | 96e41f4b71Sopenharmony_ci| modifyTime | number | 是 | 否 | 修改行数据的时间。 | 97e41f4b71Sopenharmony_ci| operation | [Flag](#flag) | 是 | 否 | 对行数据所作的操作。 | 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci## CloudType 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci表示允许出现的云数据字段类型,接口参数具体类型根据其功能而定。 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci| 类型 | 说明 | 106e41f4b71Sopenharmony_ci| ------------------------- | ------------------------------- | 107e41f4b71Sopenharmony_ci| null | 表示值的类型为空。 | 108e41f4b71Sopenharmony_ci| number | 表示值的类型为数字类型。 | 109e41f4b71Sopenharmony_ci| string | 表示值的类型为字符串类型。 | 110e41f4b71Sopenharmony_ci| boolean | 表示值的类型为布尔类型。 | 111e41f4b71Sopenharmony_ci| Uint8Array | 表示值的类型为Uint8类型的数组。 | 112e41f4b71Sopenharmony_ci| [CloudAsset](#cloudasset) | 表示值的类型为云资产类型。 | 113e41f4b71Sopenharmony_ci| [CloudAssets](#cloudassets) | 表示值的类型为云资产数组类型。 | 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci## CloudInfo 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci云信息。 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 122e41f4b71Sopenharmony_ci| --------- | --------------------------------------------------- | ---- | -------------- | 123e41f4b71Sopenharmony_ci| cloudInfo | [ServiceInfo](#serviceinfo) | 是 | 云服务信息。 | 124e41f4b71Sopenharmony_ci| apps | Record<string, [AppBriefInfo](#appbriefinfo)> | 是 | 简要应用信息。 | 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci## CloudData 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci云数据。 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 133e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | 134e41f4b71Sopenharmony_ci| nextCursor | string | 是 | 查询游标。 | 135e41f4b71Sopenharmony_ci| hasMore | boolean | 是 | 服务器是否存在更多数据可供查询,true表示服务器上还有数据等待查询,false表示服务器上不存在可查询的数据。 | 136e41f4b71Sopenharmony_ci| values | Array<Record<string, [CloudType](#cloudtype)>> | 是 | 需要查询数据的数组,包括data value(数据值)和[ExtensionValue](#extensionvalue)(扩展值)。 | 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci## AppBriefInfo 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci简要应用信息。 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 145e41f4b71Sopenharmony_ci| ----------- | ------- | ---- | ---------------------------------- | 146e41f4b71Sopenharmony_ci| appId | string | 是 | 应用程序ID。 | 147e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 148e41f4b71Sopenharmony_ci| cloudSwitch | boolean | 是 | 云开关,表示应用程序是否启用云,true表示启用云,false表示不启用云。 | 149e41f4b71Sopenharmony_ci| instanceId | number | 是 | 应用分身ID,0表示应用本身,分身ID依次递增。 | 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci## FieldType 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci描述数据库表中字段类型的枚举。请使用枚举名而非枚举值。 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 158e41f4b71Sopenharmony_ci| -------------------------------------------------- | ---- | -------------------------------------- | 159e41f4b71Sopenharmony_ci| NULL | 0 | 类型为空。 | 160e41f4b71Sopenharmony_ci| NUMBER | 1 | 数值类型。 | 161e41f4b71Sopenharmony_ci| REAL | 2 | 双精度浮点类型。 | 162e41f4b71Sopenharmony_ci| TEXT | 3 | 文本类型。 | 163e41f4b71Sopenharmony_ci| BOOL | 4 | 布尔类型。 | 164e41f4b71Sopenharmony_ci| BLOB | 5 | 二进制大对象类型,可以存储二进制文件。 | 165e41f4b71Sopenharmony_ci| [ASSET](js-apis-data-relationalStore.md#asset10) | 6 | 资产类型。 | 166e41f4b71Sopenharmony_ci| [ASSETS](js-apis-data-relationalStore.md#assets10) | 7 | 资产列表类型。 | 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci## Field 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci数据库中的字段结构。 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 175e41f4b71Sopenharmony_ci| -------- | ------------------------- | ---- | ---------------------- | 176e41f4b71Sopenharmony_ci| alias | string | 是 | 该字段在服务器表中的别名。 | 177e41f4b71Sopenharmony_ci| colName | string | 是 | 列名。 | 178e41f4b71Sopenharmony_ci| type | [FieldType](#fieldtype) | 是 | 字段类型。 | 179e41f4b71Sopenharmony_ci| primary | boolean | 是 | 表示当前列是否是主键。true表示当前列为主键,false表示当前列不为主键。 | 180e41f4b71Sopenharmony_ci| nullable | boolean | 是 | 当前列是否为空值,true表示当前列为空,false表示当前列不为空。 | 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci## Table 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci表结构信息。 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 189e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | ---------------------------- | 190e41f4b71Sopenharmony_ci| alias | string | 是 | 该表在服务器数据库中的别名。 | 191e41f4b71Sopenharmony_ci| name | string | 是 | 表名。 | 192e41f4b71Sopenharmony_ci| fields | Array<[Field](#field)> | 是 | 数据库表中的字段结构信息。 | 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci## Database 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci数据库结构信息。 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 201e41f4b71Sopenharmony_ci| ------ | ---------------------------- | ---- | -------------------------------- | 202e41f4b71Sopenharmony_ci| name | string | 是 | 数据库名称。 | 203e41f4b71Sopenharmony_ci| alias | string | 是 | 该数据库在服务器中的别名。 | 204e41f4b71Sopenharmony_ci| tables | Array<[Table](#table)> | 是 | 数据库中的表,包含数据详细信息。 | 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci## AppSchema 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci应用数据库模式。 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 213e41f4b71Sopenharmony_ci| ---------- | ------------------------------------ | ---- | ------------------ | 214e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 215e41f4b71Sopenharmony_ci| version | number | 是 | 数据库模式的版本。 | 216e41f4b71Sopenharmony_ci| databases | Array<[Database](#database)> | 是 | 应用的数据库信息。 | 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci## SubscribeId 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci订阅ID。 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 223e41f4b71Sopenharmony_ci 224e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 225e41f4b71Sopenharmony_ci| ------------- | ------ | ---- | ---------------------- | 226e41f4b71Sopenharmony_ci| databaseAlias | string | 是 | 服务器上数据库的名称。 | 227e41f4b71Sopenharmony_ci| id | string | 是 | 订阅ID。 | 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci## SubscribeInfo 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci订阅信息。 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 236e41f4b71Sopenharmony_ci| -------------- | ------------------------------------------------------------ | ---- | -------------------- | 237e41f4b71Sopenharmony_ci| expirationTime | number | 是 | 订阅过期时间(ms)。 | 238e41f4b71Sopenharmony_ci| subscribe | Record<string, Array<[SubscribeId](#subscribeid)>> | 是 | 订阅信息。 | 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci## LockInfo 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ci云数据库锁信息。 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 247e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------- | 248e41f4b71Sopenharmony_ci| interval | number | 是 | 云数据库锁的持续时间,单位为s。 | 249e41f4b71Sopenharmony_ci| lockId | number | 是 | 锁ID。 | 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci## ErrorCode 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci表示端云共享过程的状态。请使用枚举名而非枚举值。 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 258e41f4b71Sopenharmony_ci| --------------------- | ---- | ------------------------------------------------------------ | 259e41f4b71Sopenharmony_ci| SUCCESS | 0 | 表示端云同步过程成功。 | 260e41f4b71Sopenharmony_ci| UNKNOWN_ERROR | 1 | 表示端云同步过程中遇到未知错误。 | 261e41f4b71Sopenharmony_ci| NETWORK_ERROR | 2 | 表示端云同步过程中遇到网络错误。 | 262e41f4b71Sopenharmony_ci| CLOUD_DISABLED | 3 | 表示云同步开关未开启,请检查云空间同步开关状态。 | 263e41f4b71Sopenharmony_ci| LOCKED_BY_OTHERS | 4 | 表示有其他设备正在进行端云同步,本设备无法进行端云同步。请确保无其他设备占用端云资源后,在使用本设备进行端云同步任务。 | 264e41f4b71Sopenharmony_ci| RECORD_LIMIT_EXCEEDED | 5 | 表示本次端云同步需要同步的条目或大小超出最大值。由云端配置最大值。 | 265e41f4b71Sopenharmony_ci| NO_SPACE_FOR_ASSET | 6 | 表示云空间剩余空间小于待同步的资产大小。 | 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci## cloudExtension.createCloudServiceStub 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_cicreateCloudServiceStub(instance: CloudService): Promise<rpc.RemoteObject> 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci根据[CloudService](#cloudservice)类的实例创建对应的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,系统内部通过该对象调用[CloudService](#cloudservice)的实现接口,使用Promise异步回调。 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci**参数:** 276e41f4b71Sopenharmony_ci 277e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 278e41f4b71Sopenharmony_ci| --------- | ------------------------------- | ---- | -------------------------------- | 279e41f4b71Sopenharmony_ci| instance | [CloudService](#cloudservice) | 是 | [CloudService](#cloudservice)类的实例。 | 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci**返回值:** 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci| 类型 | 说明 | 284e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 285e41f4b71Sopenharmony_ci| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise对象,返回[CloudService](#cloudservice)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 | 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci**示例:** 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci```ts 290e41f4b71Sopenharmony_ciimport { Want, ServiceExtensionAbility } from '@kit.AbilityKit'; 291e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 294e41f4b71Sopenharmony_ci constructor() {} 295e41f4b71Sopenharmony_ci async connectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> { 296e41f4b71Sopenharmony_ci // ... 297e41f4b71Sopenharmony_ci } 298e41f4b71Sopenharmony_ci} 299e41f4b71Sopenharmony_ci 300e41f4b71Sopenharmony_ciexport default class MyServiceExtension extends ServiceExtensionAbility { 301e41f4b71Sopenharmony_ci onCreate(want: Want) { 302e41f4b71Sopenharmony_ci console.info(`onCreate: ${want}`); 303e41f4b71Sopenharmony_ci } 304e41f4b71Sopenharmony_ci onRequest(want: Want, startId: number) { 305e41f4b71Sopenharmony_ci console.info(`onRequest: ${want} ${startId}`); 306e41f4b71Sopenharmony_ci } 307e41f4b71Sopenharmony_ci onConnect(want: Want): rpc.RemoteObject | Promise<rpc.RemoteObject> { 308e41f4b71Sopenharmony_ci console.info(`onConnect: ${want}`); 309e41f4b71Sopenharmony_ci return cloudExtension.createCloudServiceStub(new MyCloudService()); 310e41f4b71Sopenharmony_ci } 311e41f4b71Sopenharmony_ci onDisconnect(want: Want) { 312e41f4b71Sopenharmony_ci console.info(`onDisconnect: ${want}`); 313e41f4b71Sopenharmony_ci } 314e41f4b71Sopenharmony_ci onDestroy() { 315e41f4b71Sopenharmony_ci console.info('onDestroy'); 316e41f4b71Sopenharmony_ci } 317e41f4b71Sopenharmony_ci} 318e41f4b71Sopenharmony_ci``` 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci## cloudExtension.createShareServiceStub 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_cicreateShareServiceStub(instance: ShareCenter): Promise<rpc.RemoteObject> 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci根据[ShareCenter](#sharecenter)类的实例创建对应的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,系统内部通过该对象调用[ShareCenter](#sharecenter)的实现接口,使用Promise异步回调。 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci**参数:** 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 331e41f4b71Sopenharmony_ci| --------- | ------------------------------- | ---- | -------------------------------- | 332e41f4b71Sopenharmony_ci| instance | [ShareCenter](#sharecenter) | 是 | [ShareCenter](#sharecenter)类的实例。 | 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci**返回值:** 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci| 类型 | 说明 | 337e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 338e41f4b71Sopenharmony_ci| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise对象,返回[ShareCenter](#sharecenter)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 | 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci**示例:** 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ci```ts 343e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ciexport default class MyShareCenter implements cloudExtension.ShareCenter { 346e41f4b71Sopenharmony_ci constructor() {} 347e41f4b71Sopenharmony_ci // ... 348e41f4b71Sopenharmony_ci} 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 351e41f4b71Sopenharmony_ci constructor() {} 352e41f4b71Sopenharmony_ci async connectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> { 353e41f4b71Sopenharmony_ci console.info(`connect share center, bundle: ${bundleName}`); 354e41f4b71Sopenharmony_ci return cloudExtension.createShareServiceStub(new MyShareCenter()); 355e41f4b71Sopenharmony_ci } 356e41f4b71Sopenharmony_ci} 357e41f4b71Sopenharmony_ci``` 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci## cloudExtension.createCloudDBStub 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_cicreateCloudDBStub(instance: CloudDB): Promise<rpc.RemoteObject> 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci根据[CloudDB](#clouddb)类的实例创建对应的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,系统内部通过该对象调用[CloudDB](#clouddb)的实现接口,使用Promise异步回调。 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci**参数:** 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 370e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | ------------------------------- | 371e41f4b71Sopenharmony_ci| instance | [CloudDB](#clouddb) | 是 | [CloudDB](#clouddb)类的实例。 | 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci**返回值:** 374e41f4b71Sopenharmony_ci 375e41f4b71Sopenharmony_ci| 类型 | 说明 | 376e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ | 377e41f4b71Sopenharmony_ci| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise对象,返回[CloudDB](#clouddb)的[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 | 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci```ts 380e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ciexport default class MyCloudDB implements cloudExtension.CloudDB { 383e41f4b71Sopenharmony_ci // ... 384e41f4b71Sopenharmony_ci} 385e41f4b71Sopenharmony_ci 386e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 387e41f4b71Sopenharmony_ci constructor() {} 388e41f4b71Sopenharmony_ci // ... 389e41f4b71Sopenharmony_ci async connectDB(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 390e41f4b71Sopenharmony_ci console.info(`connect DB, bundleName: ${bundleName}`); 391e41f4b71Sopenharmony_ci return cloudExtension.createCloudDBStub(new MyCloudDB()); 392e41f4b71Sopenharmony_ci } 393e41f4b71Sopenharmony_ci} 394e41f4b71Sopenharmony_ci``` 395e41f4b71Sopenharmony_ci 396e41f4b71Sopenharmony_ci## cloudExtension.createAssetLoaderStub 397e41f4b71Sopenharmony_ci 398e41f4b71Sopenharmony_cicreateAssetLoaderStub(instance: AssetLoader): Promise<rpc.RemoteObject> 399e41f4b71Sopenharmony_ci 400e41f4b71Sopenharmony_ci根据[AssetLoader](#assetloader)类的实例创建对应的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,系统内部通过该对象调用[AssetLoader](#assetloader)的实现接口,使用Promise异步回调。 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ci**参数:** 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 405e41f4b71Sopenharmony_ci| -------- | ----------------------------- | ---- | ------------------------------------------------- | 406e41f4b71Sopenharmony_ci| instance | [AssetLoader](#assetloader) | 是 | 表示一个[AssetLoader](#assetloader)类型的实例。 | 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci**返回值:** 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci| 类型 | 说明 | 413e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ | 414e41f4b71Sopenharmony_ci| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise对象,返回[AssetLoader](#assetloader)的[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 | 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci**示例:** 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci```ts 419e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ciexport default class MyAssetLoader implements cloudExtension.AssetLoader { 422e41f4b71Sopenharmony_ci // ... 423e41f4b71Sopenharmony_ci} 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 426e41f4b71Sopenharmony_ci constructor() {} 427e41f4b71Sopenharmony_ci // ... 428e41f4b71Sopenharmony_ci async connectAssetLoader(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 429e41f4b71Sopenharmony_ci console.info(`connect asset loader, bundle: ${bundleName}`); 430e41f4b71Sopenharmony_ci return cloudExtension.createAssetLoaderStub(new MyAssetLoader()); 431e41f4b71Sopenharmony_ci } 432e41f4b71Sopenharmony_ci} 433e41f4b71Sopenharmony_ci``` 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci 437e41f4b71Sopenharmony_ci## CloudDB 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci提供云数据库的操作接口的类。 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_ci### generateId 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_cigenerateId(count: number): Promise<Result<Array<string>>> 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci为插入的云数据生成ID。生成的ID具有唯一性。 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ci**参数:** 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 452e41f4b71Sopenharmony_ci| ------ | ------ | ---- | -------------------- | 453e41f4b71Sopenharmony_ci| count | number | 是 | 表示要生成ID的数量。 | 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ci**返回值:** 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci| 类型 | 说明 | 458e41f4b71Sopenharmony_ci| -------------------------------------------------------- | ------------------------------------------------------------ | 459e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<Array<string>> | Promise对象,以[Result](#resultt)结构将生成的ID以数组形式返回。 | 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci**示例:** 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci```ts 464e41f4b71Sopenharmony_ciexport default class MyCloudDB implements cloudExtension.CloudDB { 465e41f4b71Sopenharmony_ci async generateId(count: number): Promise<cloudExtension.Result<Array<string>>> { 466e41f4b71Sopenharmony_ci console.info(`generate id, count: ${count}`); 467e41f4b71Sopenharmony_ci let result = new Array<string>(); 468e41f4b71Sopenharmony_ci // ... 469e41f4b71Sopenharmony_ci return { 470e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 471e41f4b71Sopenharmony_ci description: 'generateId succeeded', 472e41f4b71Sopenharmony_ci value: result 473e41f4b71Sopenharmony_ci }; 474e41f4b71Sopenharmony_ci } 475e41f4b71Sopenharmony_ci // ... 476e41f4b71Sopenharmony_ci} 477e41f4b71Sopenharmony_ci``` 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci### update 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ciupdate(table: string, values: Array<Record<string, CloudType>>, extensions: Array<Record<string, CloudType>> ): Promise<Array<Result<Record<string, CloudType>>>> 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci通过该接口更新云上的数据。 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci**参数:** 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 490e41f4b71Sopenharmony_ci| ---------- | ------------------------------------------------------------ | ---- | ---------------------- | 491e41f4b71Sopenharmony_ci| table | string | 是 | 表名。 | 492e41f4b71Sopenharmony_ci| values | Array<Record<string, [CloudType](#cloudtype)>> | 是 | 表示要插入的数据。 | 493e41f4b71Sopenharmony_ci| extensions | Array<Record<string, [CloudType](#cloudtype)>> | 是 | 表示当前数据的扩展信息。 | 494e41f4b71Sopenharmony_ci 495e41f4b71Sopenharmony_ci**返回值:** 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci| 类型 | 说明 | 498e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | --------------------------------------- | 499e41f4b71Sopenharmony_ci| Promise<Array<[Result](#resultt)<Record<string, [CloudType](#cloudtype)>>>> | Promise对象,返回更新的数据和更新结果。 | 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci**示例:** 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci```ts 504e41f4b71Sopenharmony_ciexport default class MyCloudDB implements cloudExtension.CloudDB { 505e41f4b71Sopenharmony_ci // ... 506e41f4b71Sopenharmony_ci async update(table: string, values: Array<Record<string, cloudExtension.CloudType>>, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 507e41f4b71Sopenharmony_ci console.info(`update, table: ${table}`); 508e41f4b71Sopenharmony_ci let updateRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 509e41f4b71Sopenharmony_ci // ... 510e41f4b71Sopenharmony_ci // 返回更新数据的结果 511e41f4b71Sopenharmony_ci return updateRes; 512e41f4b71Sopenharmony_ci } 513e41f4b71Sopenharmony_ci // ... 514e41f4b71Sopenharmony_ci} 515e41f4b71Sopenharmony_ci``` 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_ci### insert 518e41f4b71Sopenharmony_ci 519e41f4b71Sopenharmony_ciinsert(table: string, values: Array<Record<string, CloudType>>, extensions: Array<Record<string, CloudType>>): Promise<Array<Result<Record<string, CloudType>>>> 520e41f4b71Sopenharmony_ci 521e41f4b71Sopenharmony_ci将数据插入云数据库表中。 522e41f4b71Sopenharmony_ci 523e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_ci**参数:** 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 528e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------------------------- | ---- | ------------------------ | 529e41f4b71Sopenharmony_ci| table | string | 是 | 表名。 | 530e41f4b71Sopenharmony_ci| values | Array<Record<string, [CloudType](#cloudtype)>> | 是 | 表示要插入的数据。 | 531e41f4b71Sopenharmony_ci| extensions | Array<Record<string, [CloudType](#cloudtype)>> | 是 | 表示当前数据的扩展信息。 | 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci**返回值:** 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ci| 类型 | 说明 | 536e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------- | 537e41f4b71Sopenharmony_ci| Promise<Array<[Result](#resultt)<Record<string, [CloudType](#cloudtype)>>>> | Promise对象,返回插入数据和插入结果。 | 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci**示例:** 540e41f4b71Sopenharmony_ci 541e41f4b71Sopenharmony_ci```ts 542e41f4b71Sopenharmony_ciexport default class MyCloudDB implements cloudExtension.CloudDB { 543e41f4b71Sopenharmony_ci // ... 544e41f4b71Sopenharmony_ci async insert(table: string, values: Array<Record<string, cloudExtension.CloudType>>, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 545e41f4b71Sopenharmony_ci console.info(`insert, table: ${table}`); 546e41f4b71Sopenharmony_ci let insertRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 547e41f4b71Sopenharmony_ci // ... 548e41f4b71Sopenharmony_ci // 返回插入数据的结果 549e41f4b71Sopenharmony_ci return insertRes; 550e41f4b71Sopenharmony_ci } 551e41f4b71Sopenharmony_ci // ... 552e41f4b71Sopenharmony_ci} 553e41f4b71Sopenharmony_ci``` 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ci### delete 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_cidelete(table: string, extensions: Array<Record<string, CloudType>> ): Promise<Array<Result<Record<string, CloudType>>>> 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_ci删除云数据库表中的指定数据。 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci**参数:** 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 566e41f4b71Sopenharmony_ci| ---------- | --------------------------------------------------------- | ---- | ------------------------ | 567e41f4b71Sopenharmony_ci| table | string | 是 | 表名。 | 568e41f4b71Sopenharmony_ci| extensions | Array<Record<string,[CloudType](#cloudtype)>> | 是 | 表示当前数据的扩展信息。 | 569e41f4b71Sopenharmony_ci 570e41f4b71Sopenharmony_ci**返回值:** 571e41f4b71Sopenharmony_ci 572e41f4b71Sopenharmony_ci| 类型 | 说明 | 573e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ----------------------------------------- | 574e41f4b71Sopenharmony_ci| Promise<Array<[Result](#resultt)<Record<string, [CloudType](#cloudtype)>>>> | Promise对象,返回被删除的数据和删除结果。 | 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci**示例:** 577e41f4b71Sopenharmony_ci 578e41f4b71Sopenharmony_ci```ts 579e41f4b71Sopenharmony_ciexport default class MyCloudDB implements cloudExtension.CloudDB { 580e41f4b71Sopenharmony_ci // ... 581e41f4b71Sopenharmony_ci async delete(table: string, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 582e41f4b71Sopenharmony_ci console.info(`delete, table: ${table}`); 583e41f4b71Sopenharmony_ci let deleteRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 584e41f4b71Sopenharmony_ci // ... 585e41f4b71Sopenharmony_ci // 返回插入数据的结果 586e41f4b71Sopenharmony_ci return deleteRes; 587e41f4b71Sopenharmony_ci } 588e41f4b71Sopenharmony_ci // ... 589e41f4b71Sopenharmony_ci} 590e41f4b71Sopenharmony_ci``` 591e41f4b71Sopenharmony_ci 592e41f4b71Sopenharmony_ci### query 593e41f4b71Sopenharmony_ci 594e41f4b71Sopenharmony_ciquery(table: string, fields: Array<string>, queryCount: number, queryCursor: string): Promise<Result<CloudData>> 595e41f4b71Sopenharmony_ci 596e41f4b71Sopenharmony_ci在云数据库表中查询数据。 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci**参数:** 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 603e41f4b71Sopenharmony_ci| ----------- | ------------- | ---- | ------------------------ | 604e41f4b71Sopenharmony_ci| table | string | 是 | 表名。 | 605e41f4b71Sopenharmony_ci| fields | Array<string> | 是 | 表示字段名。 | 606e41f4b71Sopenharmony_ci| queryCount | number | 是 | 表示要查询的数据记录数。 | 607e41f4b71Sopenharmony_ci| queryCursor | string | 是 | 表示要查询的游标。 | 608e41f4b71Sopenharmony_ci 609e41f4b71Sopenharmony_ci**返回值:** 610e41f4b71Sopenharmony_ci 611e41f4b71Sopenharmony_ci| 类型 | 说明 | 612e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | --------------------------------------- | 613e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<[CloudData](#clouddata)>> | Promise对象,返回被查询数据和查询结果。 | 614e41f4b71Sopenharmony_ci 615e41f4b71Sopenharmony_ci**示例:** 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci```ts 618e41f4b71Sopenharmony_ciexport default class MyCloudDB implements cloudExtension.CloudDB { 619e41f4b71Sopenharmony_ci // ... 620e41f4b71Sopenharmony_ci async query(table: string, fields: Array<string>, queryCount: number, queryCursor: string): Promise<cloudExtension.Result<cloudExtension.CloudData>> { 621e41f4b71Sopenharmony_ci console.info(`query, table: ${table}`); 622e41f4b71Sopenharmony_ci // ... 623e41f4b71Sopenharmony_ci // 返回插入数据的结果 624e41f4b71Sopenharmony_ci return { 625e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 626e41f4b71Sopenharmony_ci description: 'query succeeded', 627e41f4b71Sopenharmony_ci value: { 628e41f4b71Sopenharmony_ci nextCursor: "test_nextCursor", 629e41f4b71Sopenharmony_ci hasMore: true, 630e41f4b71Sopenharmony_ci values: [] 631e41f4b71Sopenharmony_ci } 632e41f4b71Sopenharmony_ci }; 633e41f4b71Sopenharmony_ci } 634e41f4b71Sopenharmony_ci // ... 635e41f4b71Sopenharmony_ci} 636e41f4b71Sopenharmony_ci``` 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci### lock 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_cilock(): Promise<Result<LockInfo>> 641e41f4b71Sopenharmony_ci 642e41f4b71Sopenharmony_ci为云数据库加锁。 643e41f4b71Sopenharmony_ci 644e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 645e41f4b71Sopenharmony_ci 646e41f4b71Sopenharmony_ci**返回值:** 647e41f4b71Sopenharmony_ci 648e41f4b71Sopenharmony_ci| 类型 | 说明 | 649e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | --------------------------------------------------- | 650e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<[LockInfo](#lockinfo)>> | Promise对象,返回加锁的信息,包含加锁时长和锁的ID。 | 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ci**示例:** 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci```ts 655e41f4b71Sopenharmony_cilet test_time: number = 10; 656e41f4b71Sopenharmony_cilet test_lockId: number = 1; 657e41f4b71Sopenharmony_ciexport default class MyCloudDB implements cloudExtension.CloudDB { 658e41f4b71Sopenharmony_ci // ... 659e41f4b71Sopenharmony_ci async lock(): Promise<cloudExtension.Result<cloudExtension.LockInfo>> { 660e41f4b71Sopenharmony_ci console.info(`DB lock`); 661e41f4b71Sopenharmony_ci // ... 662e41f4b71Sopenharmony_ci // 返回插入数据的结果 663e41f4b71Sopenharmony_ci return { 664e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 665e41f4b71Sopenharmony_ci description: 'lock succeeded', 666e41f4b71Sopenharmony_ci value: { 667e41f4b71Sopenharmony_ci interval: test_time, 668e41f4b71Sopenharmony_ci lockId: test_lockId 669e41f4b71Sopenharmony_ci } 670e41f4b71Sopenharmony_ci }; 671e41f4b71Sopenharmony_ci } 672e41f4b71Sopenharmony_ci // ... 673e41f4b71Sopenharmony_ci} 674e41f4b71Sopenharmony_ci``` 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ci### heartbeat 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_ciheartbeat(lockId: number): Promise<Result<LockInfo>> 679e41f4b71Sopenharmony_ci 680e41f4b71Sopenharmony_ci延长数据库的加锁时效。 681e41f4b71Sopenharmony_ci 682e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 683e41f4b71Sopenharmony_ci 684e41f4b71Sopenharmony_ci**参数:** 685e41f4b71Sopenharmony_ci 686e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 687e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------------- | 688e41f4b71Sopenharmony_ci| lockId | number | 是 | 表示需要延时的锁ID。 | 689e41f4b71Sopenharmony_ci 690e41f4b71Sopenharmony_ci**返回值:** 691e41f4b71Sopenharmony_ci 692e41f4b71Sopenharmony_ci| 类型 | 说明 | 693e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------- | 694e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<[LockInfo](#lockinfo)>> | Promise对象,返回锁的信息,包含加锁时长和锁的ID。 | 695e41f4b71Sopenharmony_ci 696e41f4b71Sopenharmony_ci**示例:** 697e41f4b71Sopenharmony_ci 698e41f4b71Sopenharmony_ci```ts 699e41f4b71Sopenharmony_cilet test_lockId: number = 1; 700e41f4b71Sopenharmony_cilet test_time: number = 10; 701e41f4b71Sopenharmony_ciexport default class MyCloudDB implements cloudExtension.CloudDB { 702e41f4b71Sopenharmony_ci // ... 703e41f4b71Sopenharmony_ci async heartbeat(lockId: number): Promise<cloudExtension.Result<cloudExtension.LockInfo>> { 704e41f4b71Sopenharmony_ci console.info(`heartbeat lock`); 705e41f4b71Sopenharmony_ci // ... 706e41f4b71Sopenharmony_ci // 返回插入数据的结果 707e41f4b71Sopenharmony_ci return { 708e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 709e41f4b71Sopenharmony_ci description: 'heartbeat succeeded', 710e41f4b71Sopenharmony_ci value: { 711e41f4b71Sopenharmony_ci interval: test_time, 712e41f4b71Sopenharmony_ci lockId: test_lockId 713e41f4b71Sopenharmony_ci } 714e41f4b71Sopenharmony_ci }; 715e41f4b71Sopenharmony_ci } 716e41f4b71Sopenharmony_ci // ... 717e41f4b71Sopenharmony_ci} 718e41f4b71Sopenharmony_ci``` 719e41f4b71Sopenharmony_ci 720e41f4b71Sopenharmony_ci### unlock 721e41f4b71Sopenharmony_ci 722e41f4b71Sopenharmony_ciunlock(lockId: number): Promise<Result<boolean>>; 723e41f4b71Sopenharmony_ci 724e41f4b71Sopenharmony_ci为云数据库解锁。 725e41f4b71Sopenharmony_ci 726e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_ci**参数:** 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 731e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ------------- | 732e41f4b71Sopenharmony_ci| lockId | number | 是 | 表示锁的ID。 | 733e41f4b71Sopenharmony_ci 734e41f4b71Sopenharmony_ci**返回值:** 735e41f4b71Sopenharmony_ci 736e41f4b71Sopenharmony_ci| 类型 | 说明 | 737e41f4b71Sopenharmony_ci| ------------------------------------------------ | ------------------------------------------------------------ | 738e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<boolean>> | Promise对象,返回解锁结果,true表示解锁成功,false表示解锁失败。 | 739e41f4b71Sopenharmony_ci 740e41f4b71Sopenharmony_ci**示例:** 741e41f4b71Sopenharmony_ci 742e41f4b71Sopenharmony_ci```ts 743e41f4b71Sopenharmony_ciexport default class MyCloudDB implements cloudExtension.CloudDB { 744e41f4b71Sopenharmony_ci // ... 745e41f4b71Sopenharmony_ci async unlock(lockId: number): Promise<cloudExtension.Result<boolean>> { 746e41f4b71Sopenharmony_ci console.info(`unlock`); 747e41f4b71Sopenharmony_ci // ... 748e41f4b71Sopenharmony_ci // 返回插入数据的结果 749e41f4b71Sopenharmony_ci return { 750e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 751e41f4b71Sopenharmony_ci description: 'unlock succeeded', 752e41f4b71Sopenharmony_ci value: false 753e41f4b71Sopenharmony_ci }; 754e41f4b71Sopenharmony_ci } 755e41f4b71Sopenharmony_ci // ... 756e41f4b71Sopenharmony_ci} 757e41f4b71Sopenharmony_ci``` 758e41f4b71Sopenharmony_ci 759e41f4b71Sopenharmony_ci## CloudService 760e41f4b71Sopenharmony_ci 761e41f4b71Sopenharmony_ci提供对接同步云服务的类。开发者需要继承此类并实现类的接口,系统内部通过该类的接口连接并使用同步云服务。 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci### getServiceInfo 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_cigetServiceInfo(): Promise<ServiceInfo> 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ci获取服务器上的信息。使用Promise异步回调。 768e41f4b71Sopenharmony_ci 769e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 770e41f4b71Sopenharmony_ci 771e41f4b71Sopenharmony_ci**返回值:** 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_ci| 类型 | 说明 | 774e41f4b71Sopenharmony_ci| -------------------------------------------- | ----------------------------------- | 775e41f4b71Sopenharmony_ci| Promise<[ServiceInfo](#serviceinfo)> | Promise对象,返回获取的服务器信息。 | 776e41f4b71Sopenharmony_ci 777e41f4b71Sopenharmony_ci**示例:** 778e41f4b71Sopenharmony_ci 779e41f4b71Sopenharmony_ci```ts 780e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_cilet test_space: number = 100; 783e41f4b71Sopenharmony_cilet test_userId: number = 1; 784e41f4b71Sopenharmony_ci 785e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 786e41f4b71Sopenharmony_ci constructor() {} 787e41f4b71Sopenharmony_ci // ... 788e41f4b71Sopenharmony_ci async getServiceInfo(): Promise<cloudExtension.ServiceInfo> { 789e41f4b71Sopenharmony_ci console.info(`get service info`); 790e41f4b71Sopenharmony_ci // ... 791e41f4b71Sopenharmony_ci return { 792e41f4b71Sopenharmony_ci enableCloud: true, 793e41f4b71Sopenharmony_ci id: "test_id", 794e41f4b71Sopenharmony_ci totalSpace: test_space, 795e41f4b71Sopenharmony_ci remainingSpace: test_space, 796e41f4b71Sopenharmony_ci user: test_userId, 797e41f4b71Sopenharmony_ci }; 798e41f4b71Sopenharmony_ci } 799e41f4b71Sopenharmony_ci} 800e41f4b71Sopenharmony_ci``` 801e41f4b71Sopenharmony_ci 802e41f4b71Sopenharmony_ci### getAppBriefInfo 803e41f4b71Sopenharmony_ci 804e41f4b71Sopenharmony_cigetAppBriefInfo(): Promise<Record<string, AppBriefInfo>> 805e41f4b71Sopenharmony_ci 806e41f4b71Sopenharmony_ci获取简要应用信息。使用Promise异步回调。 807e41f4b71Sopenharmony_ci 808e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci**返回值:** 811e41f4b71Sopenharmony_ci 812e41f4b71Sopenharmony_ci| 类型 | 说明 | 813e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ | 814e41f4b71Sopenharmony_ci| Promise<Record<string, [AppBriefInfo](#appbriefinfo)>>> | Promise对象,返回与bundleName和 [AppBriefInfo](#appbriefinfo)相对应的键值对。 | 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_ci**示例:** 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ci```ts 819e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 820e41f4b71Sopenharmony_ci constructor() {} 821e41f4b71Sopenharmony_ci // ... 822e41f4b71Sopenharmony_ci async getAppBriefInfo(): Promise<Record<string, cloudExtension.AppBriefInfo>> { 823e41f4b71Sopenharmony_ci console.info(`get app brief info`); 824e41f4b71Sopenharmony_ci // ... 825e41f4b71Sopenharmony_ci return { 826e41f4b71Sopenharmony_ci "test_bundle": 827e41f4b71Sopenharmony_ci { 828e41f4b71Sopenharmony_ci appId: "test_appID", 829e41f4b71Sopenharmony_ci bundleName: "test_bundlename", 830e41f4b71Sopenharmony_ci cloudSwitch: true, 831e41f4b71Sopenharmony_ci instanceId: 0, 832e41f4b71Sopenharmony_ci } 833e41f4b71Sopenharmony_ci }; 834e41f4b71Sopenharmony_ci } 835e41f4b71Sopenharmony_ci} 836e41f4b71Sopenharmony_ci``` 837e41f4b71Sopenharmony_ci 838e41f4b71Sopenharmony_ci### getAppSchema 839e41f4b71Sopenharmony_ci 840e41f4b71Sopenharmony_ci getAppSchema(bundleName: string): Promise<Result<AppSchema>> 841e41f4b71Sopenharmony_ci 842e41f4b71Sopenharmony_ci获取应用Schema(数据库模式)信息。使用Promise异步回调。 843e41f4b71Sopenharmony_ci 844e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 845e41f4b71Sopenharmony_ci 846e41f4b71Sopenharmony_ci**参数:** 847e41f4b71Sopenharmony_ci 848e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 849e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | ---------- | 850e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 851e41f4b71Sopenharmony_ci 852e41f4b71Sopenharmony_ci**返回值:** 853e41f4b71Sopenharmony_ci 854e41f4b71Sopenharmony_ci| 类型 | 说明 | 855e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------- | 856e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<[AppSchema](#appschema)>> | Promise对象,返回数据库的schema信息。 | 857e41f4b71Sopenharmony_ci 858e41f4b71Sopenharmony_ci**示例:** 859e41f4b71Sopenharmony_ci 860e41f4b71Sopenharmony_ci```ts 861e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 862e41f4b71Sopenharmony_ci constructor() { 863e41f4b71Sopenharmony_ci } 864e41f4b71Sopenharmony_ci // ... 865e41f4b71Sopenharmony_ci async getAppSchema(bundleName: string): Promise<cloudExtension.Result<cloudExtension.AppSchema>> { 866e41f4b71Sopenharmony_ci console.info(`get app schema, bundleName:${bundleName}`); 867e41f4b71Sopenharmony_ci // ... 868e41f4b71Sopenharmony_ci return { 869e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 870e41f4b71Sopenharmony_ci description: "get app schema success", 871e41f4b71Sopenharmony_ci value: { 872e41f4b71Sopenharmony_ci bundleName: "test_bundleName", 873e41f4b71Sopenharmony_ci version: 1, 874e41f4b71Sopenharmony_ci databases: [] 875e41f4b71Sopenharmony_ci } 876e41f4b71Sopenharmony_ci }; 877e41f4b71Sopenharmony_ci } 878e41f4b71Sopenharmony_ci} 879e41f4b71Sopenharmony_ci``` 880e41f4b71Sopenharmony_ci 881e41f4b71Sopenharmony_ci### subscribe 882e41f4b71Sopenharmony_ci 883e41f4b71Sopenharmony_cisubscribe(subInfo: Record<string, Array<Database>>, expirationTime: number): Promise<Result<SubscribeInfo>> 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci发起订阅,使用Promise异步回调。 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 888e41f4b71Sopenharmony_ci 889e41f4b71Sopenharmony_ci**参数:** 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 892e41f4b71Sopenharmony_ci| -------------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------ | 893e41f4b71Sopenharmony_ci| subInfo | Record<string, Array<[Database](#database)>> | 是 | 需要订阅的数据,由应用包名称和数据库信息组成的键值对。 | 894e41f4b71Sopenharmony_ci| expirationTime | number | 是 | 表示订阅到期时间。 | 895e41f4b71Sopenharmony_ci 896e41f4b71Sopenharmony_ci**返回值:** 897e41f4b71Sopenharmony_ci 898e41f4b71Sopenharmony_ci| 类型 | 说明 | 899e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ----------------------------------------------------------- | 900e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<[SubscribeInfo](#subscribeinfo)>> | Promise对象,返回订阅的结果,包含订阅的过期时间和订阅信息。 | 901e41f4b71Sopenharmony_ci 902e41f4b71Sopenharmony_ci**示例:** 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_ci```ts 905e41f4b71Sopenharmony_cilet test_time: number = 10; 906e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 907e41f4b71Sopenharmony_ci constructor() { 908e41f4b71Sopenharmony_ci } 909e41f4b71Sopenharmony_ci // ... 910e41f4b71Sopenharmony_ci async subscribe(subInfo: Record<string, Array<cloudExtension.Database>>, expirationTime: number): Promise<cloudExtension.Result<cloudExtension.SubscribeInfo>> { 911e41f4b71Sopenharmony_ci console.info 912e41f4b71Sopenharmony_ci (`subscribe expirationTime: ${expirationTime}`); 913e41f4b71Sopenharmony_ci // ... 914e41f4b71Sopenharmony_ci return { 915e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 916e41f4b71Sopenharmony_ci description: "subscribe success", 917e41f4b71Sopenharmony_ci value: { 918e41f4b71Sopenharmony_ci expirationTime: test_time, 919e41f4b71Sopenharmony_ci subscribe: {} 920e41f4b71Sopenharmony_ci } 921e41f4b71Sopenharmony_ci }; 922e41f4b71Sopenharmony_ci } 923e41f4b71Sopenharmony_ci} 924e41f4b71Sopenharmony_ci``` 925e41f4b71Sopenharmony_ci 926e41f4b71Sopenharmony_ci 927e41f4b71Sopenharmony_ci 928e41f4b71Sopenharmony_ci### unsubscribe 929e41f4b71Sopenharmony_ci 930e41f4b71Sopenharmony_ciunsubscribe(unsubscribeInfo: Record<string, Array<string>>): Promise<number> 931e41f4b71Sopenharmony_ci 932e41f4b71Sopenharmony_ci取消订阅云中的数据变更。使用Promise异步回调。 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 935e41f4b71Sopenharmony_ci 936e41f4b71Sopenharmony_ci**参数:** 937e41f4b71Sopenharmony_ci 938e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 939e41f4b71Sopenharmony_ci| --------------- | -------------------------------------- | ---- | ------------------------------------------------------------ | 940e41f4b71Sopenharmony_ci| unsubscribeInfo | Record<string, Array<string>> | 是 | 需要取消订阅的数据信息,由应用包名和数据库结构组成的键值对。 | 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci**返回值:** 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci| 类型 | 说明 | 945e41f4b71Sopenharmony_ci| --------------------- | --------------------------------------- | 946e41f4b71Sopenharmony_ci| Promise<number> | Promise对象,返回取消订阅结果的错误码。 | 947e41f4b71Sopenharmony_ci 948e41f4b71Sopenharmony_ci```ts 949e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 950e41f4b71Sopenharmony_ci constructor() { 951e41f4b71Sopenharmony_ci } 952e41f4b71Sopenharmony_ci // ... 953e41f4b71Sopenharmony_ci async unsubscribe(unsubscribeInfo: Record<string, Array<string>>): Promise<number> { 954e41f4b71Sopenharmony_ci console.info(`unsubscribe`); 955e41f4b71Sopenharmony_ci // ... 956e41f4b71Sopenharmony_ci return cloudExtension.ErrorCode.SUCCESS; 957e41f4b71Sopenharmony_ci } 958e41f4b71Sopenharmony_ci} 959e41f4b71Sopenharmony_ci``` 960e41f4b71Sopenharmony_ci 961e41f4b71Sopenharmony_ci### connectDB 962e41f4b71Sopenharmony_ci 963e41f4b71Sopenharmony_ci connectDB(bundleName: string, database: Database): Promise<rpc.RemoteObject> 964e41f4b71Sopenharmony_ci 965e41f4b71Sopenharmony_ci系统内部通过该接口获取[CloudDB](#clouddb)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,可以通过[createCloudDBStub](#cloudextensioncreateclouddbstub)接口进行创建,使用Promise异步回调。 966e41f4b71Sopenharmony_ci 967e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 968e41f4b71Sopenharmony_ci 969e41f4b71Sopenharmony_ci**参数:** 970e41f4b71Sopenharmony_ci 971e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 972e41f4b71Sopenharmony_ci| ---------- | ----------------------- | ---- | ------------------ | 973e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 974e41f4b71Sopenharmony_ci| database | [Database](#database) | 是 | 需要连接的数据库。 | 975e41f4b71Sopenharmony_ci 976e41f4b71Sopenharmony_ci**返回值:** 977e41f4b71Sopenharmony_ci 978e41f4b71Sopenharmony_ci| 类型 | 说明 | 979e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ | 980e41f4b71Sopenharmony_ci| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise对象,返回[CloudDB](#clouddb)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 | 981e41f4b71Sopenharmony_ci 982e41f4b71Sopenharmony_ci```ts 983e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 984e41f4b71Sopenharmony_ci 985e41f4b71Sopenharmony_ciexport default class MyCloudDB implements cloudExtension.CloudDB { 986e41f4b71Sopenharmony_ci // ... 987e41f4b71Sopenharmony_ci} 988e41f4b71Sopenharmony_ci 989e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 990e41f4b71Sopenharmony_ci constructor() {} 991e41f4b71Sopenharmony_ci // ... 992e41f4b71Sopenharmony_ci async connectDB(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 993e41f4b71Sopenharmony_ci console.info(`connect DB, bundleName: ${bundleName}`); 994e41f4b71Sopenharmony_ci return cloudExtension.createCloudDBStub(new MyCloudDB()); 995e41f4b71Sopenharmony_ci } 996e41f4b71Sopenharmony_ci} 997e41f4b71Sopenharmony_ci``` 998e41f4b71Sopenharmony_ci 999e41f4b71Sopenharmony_ci### connectAssetLoader 1000e41f4b71Sopenharmony_ci 1001e41f4b71Sopenharmony_ciconnectAssetLoader(bundleName: string, database: Database): Promise<rpc.RemoteObject> 1002e41f4b71Sopenharmony_ci 1003e41f4b71Sopenharmony_ci系统内部通过该接口获取[AssetLoader](#assetloader)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,可以通过[createAssetLoaderStub](#cloudextensioncreateassetloaderstub)接口进行创建,使用Promise异步回调。 1004e41f4b71Sopenharmony_ci 1005e41f4b71Sopenharmony_ci连接进行资产上传和下载的对象。 1006e41f4b71Sopenharmony_ci 1007e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1008e41f4b71Sopenharmony_ci 1009e41f4b71Sopenharmony_ci**参数:** 1010e41f4b71Sopenharmony_ci 1011e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1012e41f4b71Sopenharmony_ci| ---------- | ----------------------- | ---- | ------------------ | 1013e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 1014e41f4b71Sopenharmony_ci| database | [Database](#database) | 是 | 需要连接的数据库。 | 1015e41f4b71Sopenharmony_ci 1016e41f4b71Sopenharmony_ci**返回值:** 1017e41f4b71Sopenharmony_ci 1018e41f4b71Sopenharmony_ci| 类型 | 说明 | 1019e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ | 1020e41f4b71Sopenharmony_ci| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise对象,返回[AssetLoader](#assetloader)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 | 1021e41f4b71Sopenharmony_ci 1022e41f4b71Sopenharmony_ci```ts 1023e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 1024e41f4b71Sopenharmony_ci 1025e41f4b71Sopenharmony_ciexport default class MyAssetLoader implements cloudExtension.AssetLoader { 1026e41f4b71Sopenharmony_ci // ... 1027e41f4b71Sopenharmony_ci} 1028e41f4b71Sopenharmony_ci 1029e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 1030e41f4b71Sopenharmony_ci constructor() {} 1031e41f4b71Sopenharmony_ci async connectAssetLoader(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 1032e41f4b71Sopenharmony_ci // ... 1033e41f4b71Sopenharmony_ci console.info(`connect asset loader, bundle: ${bundleName}`); 1034e41f4b71Sopenharmony_ci return cloudExtension.createAssetLoaderStub(new MyAssetLoader()); 1035e41f4b71Sopenharmony_ci } 1036e41f4b71Sopenharmony_ci} 1037e41f4b71Sopenharmony_ci``` 1038e41f4b71Sopenharmony_ci 1039e41f4b71Sopenharmony_ci### connectShareCenter 1040e41f4b71Sopenharmony_ci 1041e41f4b71Sopenharmony_ciconnectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> 1042e41f4b71Sopenharmony_ci 1043e41f4b71Sopenharmony_ci系统内部通过该接口获取[ShareCenter](#sharecenter)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象,可以通过[createShareServiceStub](#cloudextensioncreateshareservicestub)接口进行创建,使用Promise异步回调。 1044e41f4b71Sopenharmony_ci 1045e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1046e41f4b71Sopenharmony_ci 1047e41f4b71Sopenharmony_ci**参数:** 1048e41f4b71Sopenharmony_ci 1049e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1050e41f4b71Sopenharmony_ci| ------- | ----------------------- | ---- | ----------------------------------------------- | 1051e41f4b71Sopenharmony_ci| userId | number | 是 | 表示用户ID。 | 1052e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 1053e41f4b71Sopenharmony_ci 1054e41f4b71Sopenharmony_ci**返回值:** 1055e41f4b71Sopenharmony_ci 1056e41f4b71Sopenharmony_ci| 类型 | 说明 | 1057e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------------ | 1058e41f4b71Sopenharmony_ci| Promise<[rpc.RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)> | Promise对象,返回[ShareCenter](#sharecenter)的[RemoteObject](../apis-ipc-kit/js-apis-rpc.md#remoteobject)对象。 | 1059e41f4b71Sopenharmony_ci 1060e41f4b71Sopenharmony_ci**示例:** 1061e41f4b71Sopenharmony_ci 1062e41f4b71Sopenharmony_ci```ts 1063e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 1064e41f4b71Sopenharmony_ci 1065e41f4b71Sopenharmony_ciexport default class MyShareCenter implements cloudExtension.ShareCenter { 1066e41f4b71Sopenharmony_ci constructor() {} 1067e41f4b71Sopenharmony_ci // ... 1068e41f4b71Sopenharmony_ci} 1069e41f4b71Sopenharmony_ci 1070e41f4b71Sopenharmony_ciexport default class MyCloudService implements cloudExtension.CloudService { 1071e41f4b71Sopenharmony_ci constructor() {} 1072e41f4b71Sopenharmony_ci async connectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> { 1073e41f4b71Sopenharmony_ci console.info(`connect share center, bundle: ${bundleName}`); 1074e41f4b71Sopenharmony_ci return cloudExtension.createShareServiceStub(new MyShareCenter()); 1075e41f4b71Sopenharmony_ci } 1076e41f4b71Sopenharmony_ci} 1077e41f4b71Sopenharmony_ci``` 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci## AssetLoader 1080e41f4b71Sopenharmony_ci 1081e41f4b71Sopenharmony_ci提供资产的上传下载接口的类。 1082e41f4b71Sopenharmony_ci 1083e41f4b71Sopenharmony_ci### download 1084e41f4b71Sopenharmony_ci 1085e41f4b71Sopenharmony_cidownload(table: string, gid: string, prefix: string, assets: Array<CloudAsset>): Promise<Array<Result<CloudAsset>>> 1086e41f4b71Sopenharmony_ci 1087e41f4b71Sopenharmony_ci通过该接口实现资产的下载。 1088e41f4b71Sopenharmony_ci 1089e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1090e41f4b71Sopenharmony_ci 1091e41f4b71Sopenharmony_ci**参数:** 1092e41f4b71Sopenharmony_ci 1093e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1094e41f4b71Sopenharmony_ci| ------ | -------------------------------------- | ---- | -------------------------- | 1095e41f4b71Sopenharmony_ci| table | string | 是 | 表名。 | 1096e41f4b71Sopenharmony_ci| gid | string | 是 | 数据上云后生成的唯一标记。 | 1097e41f4b71Sopenharmony_ci| prefix | string | 是 | 表示前缀信息。 | 1098e41f4b71Sopenharmony_ci| assets | Array<[CloudAsset](#cloudasset)> | 是 | 表示需要下载的资产。 | 1099e41f4b71Sopenharmony_ci 1100e41f4b71Sopenharmony_ci**返回值:** 1101e41f4b71Sopenharmony_ci 1102e41f4b71Sopenharmony_ci| 类型 | 说明 | 1103e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | ------------------------------------------------------- | 1104e41f4b71Sopenharmony_ci| Promise<Array<[Result](resultt)<[CloudAsset](#cloudasset)>>> | Promise对象,返回资产下载结果,包含资产ID和资产哈希值。 | 1105e41f4b71Sopenharmony_ci 1106e41f4b71Sopenharmony_ci**示例:** 1107e41f4b71Sopenharmony_ci 1108e41f4b71Sopenharmony_ci```ts 1109e41f4b71Sopenharmony_ciexport default class MyAssetLoader implements cloudExtension.AssetLoader { 1110e41f4b71Sopenharmony_ci async download(table: string, gid: string, prefix: string, assets: Array<cloudExtension.CloudAsset>): Promise<Array<cloudExtension.Result<cloudExtension.CloudAsset>>> { 1111e41f4b71Sopenharmony_ci console.info(`download asset loader, table: ${table}, gid: ${gid}, prefix: ${prefix}`); 1112e41f4b71Sopenharmony_ci let downloadRes = Array<cloudExtension.Result<cloudExtension.CloudAsset>>(); 1113e41f4b71Sopenharmony_ci // ... 1114e41f4b71Sopenharmony_ci return downloadRes; 1115e41f4b71Sopenharmony_ci } 1116e41f4b71Sopenharmony_ci} 1117e41f4b71Sopenharmony_ci``` 1118e41f4b71Sopenharmony_ci 1119e41f4b71Sopenharmony_ci### upload 1120e41f4b71Sopenharmony_ci 1121e41f4b71Sopenharmony_ciupload(table: string, gid: string, assets: Array<CloudAsset>): Promise<Array<Result<CloudAsset>>> 1122e41f4b71Sopenharmony_ci 1123e41f4b71Sopenharmony_ci通过该接口实现资产的上传。 1124e41f4b71Sopenharmony_ci 1125e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1126e41f4b71Sopenharmony_ci 1127e41f4b71Sopenharmony_ci**参数:** 1128e41f4b71Sopenharmony_ci 1129e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1130e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- | ---- | ------------------------------------ | 1131e41f4b71Sopenharmony_ci| table | string | 是 | 表名。 | 1132e41f4b71Sopenharmony_ci| gid | string | 是 | 表示 GID,数据上云后生成的唯一标记。 | 1133e41f4b71Sopenharmony_ci| assets | Array<[CloudAsset](#cloudasset)> | 是 | 表示需要上传的资产。 | 1134e41f4b71Sopenharmony_ci 1135e41f4b71Sopenharmony_ci**返回值:** 1136e41f4b71Sopenharmony_ci 1137e41f4b71Sopenharmony_ci| 类型 | 说明 | 1138e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | --------------------------------------------------------- | 1139e41f4b71Sopenharmony_ci| Promise<Array<[Result](#resultt)<[CloudAsset](#cloudasset)>>> | Promise对象,返回资产上云的结果,包含资产ID和资产哈希值。 | 1140e41f4b71Sopenharmony_ci 1141e41f4b71Sopenharmony_ci**示例:** 1142e41f4b71Sopenharmony_ci 1143e41f4b71Sopenharmony_ci```ts 1144e41f4b71Sopenharmony_ciexport default class MyAssetLoader implements cloudExtension.AssetLoader { 1145e41f4b71Sopenharmony_ci async upload(table: string, gid: string, assets: Array<cloudExtension.CloudAsset>): Promise<Array<cloudExtension.Result<cloudExtension.CloudAsset>>> { 1146e41f4b71Sopenharmony_ci console.info(`upload asset loader, table: ${table}, gid: ${gid}`); 1147e41f4b71Sopenharmony_ci let uploadRes = Array<cloudExtension.Result<cloudExtension.CloudAsset>>(); 1148e41f4b71Sopenharmony_ci // ... 1149e41f4b71Sopenharmony_ci return uploadRes; 1150e41f4b71Sopenharmony_ci } 1151e41f4b71Sopenharmony_ci // ... 1152e41f4b71Sopenharmony_ci} 1153e41f4b71Sopenharmony_ci``` 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_ci## ShareCenter 1156e41f4b71Sopenharmony_ci 1157e41f4b71Sopenharmony_ci提供对接共享云服务的类。开发者需要继承此类并实现类的接口,系统内部通过该类的接口联接并使用共享云服务,实现端云共享的发起、取消或退出等能力。 1158e41f4b71Sopenharmony_ci 1159e41f4b71Sopenharmony_ci### share 1160e41f4b71Sopenharmony_ci 1161e41f4b71Sopenharmony_cishare(userId: number, bundleName: string, sharingResource: string, participants: Array<cloudData.sharing.Participant>): Promise<Result<Array<Result<cloudData.sharing.Participant>>>> 1162e41f4b71Sopenharmony_ci 1163e41f4b71Sopenharmony_ci发起端云共享邀请。共享邀请时,会指定当前发起共享的应用、共享数据的资源标识和共享参与者,使用Promise异步回调。 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1166e41f4b71Sopenharmony_ci 1167e41f4b71Sopenharmony_ci**参数:** 1168e41f4b71Sopenharmony_ci 1169e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1170e41f4b71Sopenharmony_ci| ------- | ----------------------- | ---- | ----------------------------------------------- | 1171e41f4b71Sopenharmony_ci| userId | number | 是 | 表示用户ID。 | 1172e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 1173e41f4b71Sopenharmony_ci| sharingResource | string | 是 | 端云共享资源的标识。 | 1174e41f4b71Sopenharmony_ci| participants | Array<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)> | 是 | 端云共享参与者。 | 1175e41f4b71Sopenharmony_ci 1176e41f4b71Sopenharmony_ci**返回值:** 1177e41f4b71Sopenharmony_ci 1178e41f4b71Sopenharmony_ci| 类型 | 说明 | 1179e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 1180e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<Array<[Result](#resultt)<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)>>>> | Promise对象,返回发起共享的结果。 | 1181e41f4b71Sopenharmony_ci 1182e41f4b71Sopenharmony_ci**示例:** 1183e41f4b71Sopenharmony_ci 1184e41f4b71Sopenharmony_ci```ts 1185e41f4b71Sopenharmony_ciimport { cloudData } from '@kit.ArkData'; 1186e41f4b71Sopenharmony_ci 1187e41f4b71Sopenharmony_citype Participant = cloudData.sharing.Participant; 1188e41f4b71Sopenharmony_ci 1189e41f4b71Sopenharmony_ciexport default class MyShareCenter implements cloudExtension.ShareCenter { 1190e41f4b71Sopenharmony_ci constructor() {} 1191e41f4b71Sopenharmony_ci async share(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1192e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1193e41f4b71Sopenharmony_ci console.info(`share, bundle: ${bundleName}`); 1194e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得共享的返回值 1195e41f4b71Sopenharmony_ci // ... 1196e41f4b71Sopenharmony_ci // 返回服务端发起共享的返回结果 1197e41f4b71Sopenharmony_ci let result: Array<cloudExtension.Result<Participant>> = []; 1198e41f4b71Sopenharmony_ci participants.forEach((item => { 1199e41f4b71Sopenharmony_ci result.push({ 1200e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1201e41f4b71Sopenharmony_ci description: 'share succeeded' 1202e41f4b71Sopenharmony_ci }) 1203e41f4b71Sopenharmony_ci })) 1204e41f4b71Sopenharmony_ci return { 1205e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1206e41f4b71Sopenharmony_ci description: 'share succeeded', 1207e41f4b71Sopenharmony_ci value: result 1208e41f4b71Sopenharmony_ci } 1209e41f4b71Sopenharmony_ci } 1210e41f4b71Sopenharmony_ci // ... 1211e41f4b71Sopenharmony_ci} 1212e41f4b71Sopenharmony_ci``` 1213e41f4b71Sopenharmony_ci 1214e41f4b71Sopenharmony_ci### unshare 1215e41f4b71Sopenharmony_ci 1216e41f4b71Sopenharmony_ciunshare(userId: number, bundleName: string, sharingResource: string, participants: Array<cloudData.sharing.Participant>): Promise<Result<Array<Result<cloudData.sharing.Participant>>>> 1217e41f4b71Sopenharmony_ci 1218e41f4b71Sopenharmony_ci取消端云共享。取消共享时,会指定当前取消共享的应用、取消共享数据的资源标识和取消共享的参与者,使用Promise异步回调。 1219e41f4b71Sopenharmony_ci 1220e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1221e41f4b71Sopenharmony_ci 1222e41f4b71Sopenharmony_ci**参数:** 1223e41f4b71Sopenharmony_ci 1224e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1225e41f4b71Sopenharmony_ci| ------- | ----------------------- | ---- | ----------------------------------------------- | 1226e41f4b71Sopenharmony_ci| userId | number | 是 | 表示用户ID。 | 1227e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 1228e41f4b71Sopenharmony_ci| sharingResource | string | 是 | 端云共享资源标识。 | 1229e41f4b71Sopenharmony_ci| participants | Array<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)> | 是 | 端云共享参与者。 | 1230e41f4b71Sopenharmony_ci 1231e41f4b71Sopenharmony_ci**返回值:** 1232e41f4b71Sopenharmony_ci 1233e41f4b71Sopenharmony_ci| 类型 | 说明 | 1234e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 1235e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<Array<[Result](#resultt)<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)>>>> | Promise对象,返回取消共享的结果。 | 1236e41f4b71Sopenharmony_ci 1237e41f4b71Sopenharmony_ci**示例:** 1238e41f4b71Sopenharmony_ci 1239e41f4b71Sopenharmony_ci```ts 1240e41f4b71Sopenharmony_ciimport { cloudData } from '@kit.ArkData'; 1241e41f4b71Sopenharmony_ci 1242e41f4b71Sopenharmony_citype Participant = cloudData.sharing.Participant; 1243e41f4b71Sopenharmony_ci 1244e41f4b71Sopenharmony_ciexport default class MyShareCenter implements cloudExtension.ShareCenter { 1245e41f4b71Sopenharmony_ci constructor() {} 1246e41f4b71Sopenharmony_ci async unshare(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1247e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1248e41f4b71Sopenharmony_ci console.info(`unshare, bundle: ${bundleName}`); 1249e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得取消共享的返回值 1250e41f4b71Sopenharmony_ci // ... 1251e41f4b71Sopenharmony_ci // 返回服务端取消共享的返回结果 1252e41f4b71Sopenharmony_ci let result: Array<cloudExtension.Result<Participant>> = []; 1253e41f4b71Sopenharmony_ci participants.forEach((item => { 1254e41f4b71Sopenharmony_ci result.push({ 1255e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1256e41f4b71Sopenharmony_ci description: 'unshare succeeded' 1257e41f4b71Sopenharmony_ci }) 1258e41f4b71Sopenharmony_ci })) 1259e41f4b71Sopenharmony_ci return { 1260e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1261e41f4b71Sopenharmony_ci description: 'unshare succeeded', 1262e41f4b71Sopenharmony_ci value: result 1263e41f4b71Sopenharmony_ci } 1264e41f4b71Sopenharmony_ci } 1265e41f4b71Sopenharmony_ci // ... 1266e41f4b71Sopenharmony_ci} 1267e41f4b71Sopenharmony_ci``` 1268e41f4b71Sopenharmony_ci 1269e41f4b71Sopenharmony_ci### exit 1270e41f4b71Sopenharmony_ci 1271e41f4b71Sopenharmony_ciexit(userId: number, bundleName: string, sharingResource: string): Promise<Result<void>> 1272e41f4b71Sopenharmony_ci 1273e41f4b71Sopenharmony_ci退出端云共享。退出共享时,会指定当前退出共享的应用以及退出共享数据的资源标识,使用Promise异步回调。 1274e41f4b71Sopenharmony_ci 1275e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1276e41f4b71Sopenharmony_ci 1277e41f4b71Sopenharmony_ci**参数:** 1278e41f4b71Sopenharmony_ci 1279e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1280e41f4b71Sopenharmony_ci| ------- | ----------------------- | ---- | ----------------------------------------------- | 1281e41f4b71Sopenharmony_ci| userId | number | 是 | 表示用户ID。 | 1282e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 1283e41f4b71Sopenharmony_ci| sharingResource | string | 是 | 端云共享资源标识。 | 1284e41f4b71Sopenharmony_ci 1285e41f4b71Sopenharmony_ci**返回值:** 1286e41f4b71Sopenharmony_ci 1287e41f4b71Sopenharmony_ci| 类型 | 说明 | 1288e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 1289e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<void>> | Promise对象,返回退出共享的结果。 | 1290e41f4b71Sopenharmony_ci 1291e41f4b71Sopenharmony_ci**示例:** 1292e41f4b71Sopenharmony_ci 1293e41f4b71Sopenharmony_ci```ts 1294e41f4b71Sopenharmony_ciimport { cloudData } from '@kit.ArkData'; 1295e41f4b71Sopenharmony_ci 1296e41f4b71Sopenharmony_ciexport default class MyShareCenter implements cloudExtension.ShareCenter { 1297e41f4b71Sopenharmony_ci constructor() {} 1298e41f4b71Sopenharmony_ci async exit(userId: number, bundleName: string, sharingResource: string): 1299e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<void>> { 1300e41f4b71Sopenharmony_ci console.info(`exit share, bundle: ${bundleName}`); 1301e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得退出共享的返回值 1302e41f4b71Sopenharmony_ci // ... 1303e41f4b71Sopenharmony_ci // 返回服务端退出共享的返回结果 1304e41f4b71Sopenharmony_ci return { 1305e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1306e41f4b71Sopenharmony_ci description: 'exit share succeeded' 1307e41f4b71Sopenharmony_ci } 1308e41f4b71Sopenharmony_ci } 1309e41f4b71Sopenharmony_ci // ... 1310e41f4b71Sopenharmony_ci} 1311e41f4b71Sopenharmony_ci``` 1312e41f4b71Sopenharmony_ci 1313e41f4b71Sopenharmony_ci### changePrivilege 1314e41f4b71Sopenharmony_ci 1315e41f4b71Sopenharmony_cichangePrivilege(userId: number, bundleName: string, sharingResource: string, participants: Array<cloudData.sharing.Participant>): Promise<Result<Array<Result<cloudData.sharing.Participant>>>> 1316e41f4b71Sopenharmony_ci 1317e41f4b71Sopenharmony_ci更改已共享数据的操作权限。更改权限时,会指定当前更改权限的应用、更改权限数据的资源标识和更改权限的参与者,使用Promise异步回调。 1318e41f4b71Sopenharmony_ci 1319e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1320e41f4b71Sopenharmony_ci 1321e41f4b71Sopenharmony_ci**参数:** 1322e41f4b71Sopenharmony_ci 1323e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1324e41f4b71Sopenharmony_ci| ------- | ----------------------- | ---- | ----------------------------------------------- | 1325e41f4b71Sopenharmony_ci| userId | number | 是 | 表示用户ID。 | 1326e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 1327e41f4b71Sopenharmony_ci| sharingResource | string | 是 | 端云共享资源标识。 | 1328e41f4b71Sopenharmony_ci| participants | Array<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)> | 是 | 端云共享参与者。 | 1329e41f4b71Sopenharmony_ci 1330e41f4b71Sopenharmony_ci**返回值:** 1331e41f4b71Sopenharmony_ci 1332e41f4b71Sopenharmony_ci| 类型 | 说明 | 1333e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 1334e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<Array<[Result](#resultt)<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)>>>> | Promise对象,返回更改权限的结果。 | 1335e41f4b71Sopenharmony_ci 1336e41f4b71Sopenharmony_ci**示例:** 1337e41f4b71Sopenharmony_ci 1338e41f4b71Sopenharmony_ci```ts 1339e41f4b71Sopenharmony_ciimport { cloudData } from '@kit.ArkData'; 1340e41f4b71Sopenharmony_ci 1341e41f4b71Sopenharmony_citype Participant = cloudData.sharing.Participant; 1342e41f4b71Sopenharmony_ci 1343e41f4b71Sopenharmony_ciexport default class MyShareCenter implements cloudExtension.ShareCenter { 1344e41f4b71Sopenharmony_ci constructor() {} 1345e41f4b71Sopenharmony_ci async changePrivilege(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1346e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1347e41f4b71Sopenharmony_ci console.info(`change privilege, bundle: ${bundleName}`); 1348e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得更改权限的返回值 1349e41f4b71Sopenharmony_ci // ... 1350e41f4b71Sopenharmony_ci // 返回服务端更改权限的返回结果 1351e41f4b71Sopenharmony_ci let result: Array<cloudExtension.Result<Participant>> = []; 1352e41f4b71Sopenharmony_ci participants.forEach((item => { 1353e41f4b71Sopenharmony_ci result.push({ 1354e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1355e41f4b71Sopenharmony_ci description: 'change privilege succeeded' 1356e41f4b71Sopenharmony_ci }) 1357e41f4b71Sopenharmony_ci })) 1358e41f4b71Sopenharmony_ci return { 1359e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1360e41f4b71Sopenharmony_ci description: 'change privilege succeeded', 1361e41f4b71Sopenharmony_ci value: result 1362e41f4b71Sopenharmony_ci } 1363e41f4b71Sopenharmony_ci } 1364e41f4b71Sopenharmony_ci // ... 1365e41f4b71Sopenharmony_ci} 1366e41f4b71Sopenharmony_ci``` 1367e41f4b71Sopenharmony_ci 1368e41f4b71Sopenharmony_ci### queryParticipants 1369e41f4b71Sopenharmony_ci 1370e41f4b71Sopenharmony_ciqueryParticipants(userId: number, bundleName: string, sharingResource: string): Promise<Result<Array<cloudData.sharing.Participant>>> 1371e41f4b71Sopenharmony_ci 1372e41f4b71Sopenharmony_ci查询当前端云共享的参与者。查询时,会指定当前查询参与者的应用、查询参与者数据的资源标识,使用Promise异步回调。 1373e41f4b71Sopenharmony_ci 1374e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1375e41f4b71Sopenharmony_ci 1376e41f4b71Sopenharmony_ci**参数:** 1377e41f4b71Sopenharmony_ci 1378e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1379e41f4b71Sopenharmony_ci| ------- | ----------------------- | ---- | ----------------------------------------------- | 1380e41f4b71Sopenharmony_ci| userId | number | 是 | 表示用户ID。 | 1381e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 1382e41f4b71Sopenharmony_ci| sharingResource | string | 是 | 端云共享资源标识。 | 1383e41f4b71Sopenharmony_ci 1384e41f4b71Sopenharmony_ci**返回值:** 1385e41f4b71Sopenharmony_ci 1386e41f4b71Sopenharmony_ci| 类型 | 说明 | 1387e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | --------------------------------------- | 1388e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<Array<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)>>> | Promise对象,返回查询共享参与者的结果。 | 1389e41f4b71Sopenharmony_ci 1390e41f4b71Sopenharmony_ci**示例:** 1391e41f4b71Sopenharmony_ci 1392e41f4b71Sopenharmony_ci```ts 1393e41f4b71Sopenharmony_ciimport { cloudData } from '@kit.ArkData'; 1394e41f4b71Sopenharmony_ci 1395e41f4b71Sopenharmony_citype Participant = cloudData.sharing.Participant; 1396e41f4b71Sopenharmony_ci 1397e41f4b71Sopenharmony_ciexport default class MyShareCenter implements cloudExtension.ShareCenter { 1398e41f4b71Sopenharmony_ci constructor() {} 1399e41f4b71Sopenharmony_ci async queryParticipants(userId: number, bundleName: string, sharingResource: string): 1400e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<Array<Participant>>> { 1401e41f4b71Sopenharmony_ci console.info(`query participants, bundle: ${bundleName}`); 1402e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得查询参与者的返回值 1403e41f4b71Sopenharmony_ci // ... 1404e41f4b71Sopenharmony_ci // 返回服务端查询参与者的返回结果 1405e41f4b71Sopenharmony_ci let participants = new Array<cloudData.sharing.Participant>(); 1406e41f4b71Sopenharmony_ci participants.push({ 1407e41f4b71Sopenharmony_ci identity: '000000000', 1408e41f4b71Sopenharmony_ci role: cloudData.sharing.Role.ROLE_INVITEE, 1409e41f4b71Sopenharmony_ci state: cloudData.sharing.State.STATE_ACCEPTED, 1410e41f4b71Sopenharmony_ci privilege: { 1411e41f4b71Sopenharmony_ci writable: false, 1412e41f4b71Sopenharmony_ci readable: true, 1413e41f4b71Sopenharmony_ci creatable: false, 1414e41f4b71Sopenharmony_ci deletable: false, 1415e41f4b71Sopenharmony_ci shareable: false 1416e41f4b71Sopenharmony_ci }, 1417e41f4b71Sopenharmony_ci attachInfo: '' 1418e41f4b71Sopenharmony_ci }) 1419e41f4b71Sopenharmony_ci participants.push({ 1420e41f4b71Sopenharmony_ci identity: '111111111', 1421e41f4b71Sopenharmony_ci role: cloudData.sharing.Role.ROLE_INVITEE, 1422e41f4b71Sopenharmony_ci state: cloudData.sharing.State.STATE_ACCEPTED, 1423e41f4b71Sopenharmony_ci privilege: { 1424e41f4b71Sopenharmony_ci writable: false, 1425e41f4b71Sopenharmony_ci readable: true, 1426e41f4b71Sopenharmony_ci creatable: false, 1427e41f4b71Sopenharmony_ci deletable: false, 1428e41f4b71Sopenharmony_ci shareable: false 1429e41f4b71Sopenharmony_ci }, 1430e41f4b71Sopenharmony_ci attachInfo: '' 1431e41f4b71Sopenharmony_ci }) 1432e41f4b71Sopenharmony_ci return { 1433e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1434e41f4b71Sopenharmony_ci description: 'query participants succeeded', 1435e41f4b71Sopenharmony_ci value: participants 1436e41f4b71Sopenharmony_ci } 1437e41f4b71Sopenharmony_ci } 1438e41f4b71Sopenharmony_ci // ... 1439e41f4b71Sopenharmony_ci} 1440e41f4b71Sopenharmony_ci``` 1441e41f4b71Sopenharmony_ci 1442e41f4b71Sopenharmony_ci### queryParticipantsByInvitation 1443e41f4b71Sopenharmony_ci 1444e41f4b71Sopenharmony_ciqueryParticipantsByInvitation(userId: number, bundleName: string, invitationCode: string): Promise<Result<Array<cloudData.sharing.Participant>>> 1445e41f4b71Sopenharmony_ci 1446e41f4b71Sopenharmony_ci根据邀请码查询当前端云共享的参与者。查询时,会指定当前查询参与者的应用、共享数据的邀请码,使用Promise异步回调。 1447e41f4b71Sopenharmony_ci 1448e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1449e41f4b71Sopenharmony_ci 1450e41f4b71Sopenharmony_ci**参数:** 1451e41f4b71Sopenharmony_ci 1452e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1453e41f4b71Sopenharmony_ci| ------- | ----------------------- | ---- | ----------------------------------------------- | 1454e41f4b71Sopenharmony_ci| userId | number | 是 | 表示用户ID。 | 1455e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 1456e41f4b71Sopenharmony_ci| invitationCode | string | 是 | 端云共享邀请码。 | 1457e41f4b71Sopenharmony_ci 1458e41f4b71Sopenharmony_ci**返回值:** 1459e41f4b71Sopenharmony_ci 1460e41f4b71Sopenharmony_ci| 类型 | 说明 | 1461e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 1462e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<Array<[cloudData.sharing.Participant](js-apis-data-cloudData-sys.md#participant11)>>> | Promise对象,返回根据邀请码查询共享参与者的结果。 | 1463e41f4b71Sopenharmony_ci 1464e41f4b71Sopenharmony_ci**示例:** 1465e41f4b71Sopenharmony_ci 1466e41f4b71Sopenharmony_ci```ts 1467e41f4b71Sopenharmony_ciimport { cloudData } from '@kit.ArkData'; 1468e41f4b71Sopenharmony_ci 1469e41f4b71Sopenharmony_citype Participant = cloudData.sharing.Participant; 1470e41f4b71Sopenharmony_ci 1471e41f4b71Sopenharmony_ciexport default class MyShareCenter implements cloudExtension.ShareCenter { 1472e41f4b71Sopenharmony_ci constructor() {} 1473e41f4b71Sopenharmony_ci async queryParticipantsByInvitation(userId: number, bundleName: string, invitationCode: string): 1474e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<Array<Participant>>> { 1475e41f4b71Sopenharmony_ci console.info(`query participants by invitation, bundle: ${bundleName}`); 1476e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得查询参与者的返回值 1477e41f4b71Sopenharmony_ci // ... 1478e41f4b71Sopenharmony_ci // 返回服务端查询参与者的返回结果 1479e41f4b71Sopenharmony_ci let participants = new Array<cloudData.sharing.Participant>(); 1480e41f4b71Sopenharmony_ci participants.push({ 1481e41f4b71Sopenharmony_ci identity: '000000000', 1482e41f4b71Sopenharmony_ci role: cloudData.sharing.Role.ROLE_INVITEE, 1483e41f4b71Sopenharmony_ci state: cloudData.sharing.State.STATE_ACCEPTED, 1484e41f4b71Sopenharmony_ci privilege: { 1485e41f4b71Sopenharmony_ci writable: false, 1486e41f4b71Sopenharmony_ci readable: true, 1487e41f4b71Sopenharmony_ci creatable: false, 1488e41f4b71Sopenharmony_ci deletable: false, 1489e41f4b71Sopenharmony_ci shareable: false 1490e41f4b71Sopenharmony_ci }, 1491e41f4b71Sopenharmony_ci attachInfo: '' 1492e41f4b71Sopenharmony_ci }) 1493e41f4b71Sopenharmony_ci participants.push({ 1494e41f4b71Sopenharmony_ci identity: '111111111', 1495e41f4b71Sopenharmony_ci role: cloudData.sharing.Role.ROLE_INVITEE, 1496e41f4b71Sopenharmony_ci state: cloudData.sharing.State.STATE_ACCEPTED, 1497e41f4b71Sopenharmony_ci privilege: { 1498e41f4b71Sopenharmony_ci writable: false, 1499e41f4b71Sopenharmony_ci readable: true, 1500e41f4b71Sopenharmony_ci creatable: false, 1501e41f4b71Sopenharmony_ci deletable: false, 1502e41f4b71Sopenharmony_ci shareable: false 1503e41f4b71Sopenharmony_ci }, 1504e41f4b71Sopenharmony_ci attachInfo: '' 1505e41f4b71Sopenharmony_ci }) 1506e41f4b71Sopenharmony_ci return { 1507e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1508e41f4b71Sopenharmony_ci description: 'query participants by invitation succeeded', 1509e41f4b71Sopenharmony_ci value: participants 1510e41f4b71Sopenharmony_ci } 1511e41f4b71Sopenharmony_ci } 1512e41f4b71Sopenharmony_ci // ... 1513e41f4b71Sopenharmony_ci} 1514e41f4b71Sopenharmony_ci``` 1515e41f4b71Sopenharmony_ci 1516e41f4b71Sopenharmony_ci### confirmInvitation 1517e41f4b71Sopenharmony_ci 1518e41f4b71Sopenharmony_ciconfirmInvitation(userId: number, bundleName: string, invitationCode: string, state: cloudData.sharing.State): Promise<Result<string>> 1519e41f4b71Sopenharmony_ci 1520e41f4b71Sopenharmony_ci被邀请者确认端云共享邀请。确认时,会指定当前确认邀请的应用、共享数据的邀请码以及确认状态,使用Promise异步回调。 1521e41f4b71Sopenharmony_ci 1522e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1523e41f4b71Sopenharmony_ci 1524e41f4b71Sopenharmony_ci**参数:** 1525e41f4b71Sopenharmony_ci 1526e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1527e41f4b71Sopenharmony_ci| ------- | ----------------------- | ---- | ----------------------------------------------- | 1528e41f4b71Sopenharmony_ci| userId | number | 是 | 表示用户ID。 | 1529e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 1530e41f4b71Sopenharmony_ci| invitationCode | string | 是 | 端云共享邀请码。 | 1531e41f4b71Sopenharmony_ci| state | [cloudData.sharing.State](js-apis-data-cloudData-sys.md#state11) | 是 | 共享邀请的确认状态。 | 1532e41f4b71Sopenharmony_ci 1533e41f4b71Sopenharmony_ci**返回值:** 1534e41f4b71Sopenharmony_ci 1535e41f4b71Sopenharmony_ci| 类型 | 说明 | 1536e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 1537e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<string>> | Promise对象,返回确认端云共享邀请数据的共享资源标识。 | 1538e41f4b71Sopenharmony_ci 1539e41f4b71Sopenharmony_ci**示例:** 1540e41f4b71Sopenharmony_ci 1541e41f4b71Sopenharmony_ci```ts 1542e41f4b71Sopenharmony_ciimport { cloudData } from '@kit.ArkData'; 1543e41f4b71Sopenharmony_ci 1544e41f4b71Sopenharmony_ciexport default class MyShareCenter implements cloudExtension.ShareCenter { 1545e41f4b71Sopenharmony_ci constructor() {} 1546e41f4b71Sopenharmony_ci async confirmInvitation(userId: number, bundleName: string, invitationCode: string, state: cloudData.sharing.State): 1547e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<string>> { 1548e41f4b71Sopenharmony_ci console.info(`confirm invitation, bundle: ${bundleName}`); 1549e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得确认共享邀请的返回值 1550e41f4b71Sopenharmony_ci // ... 1551e41f4b71Sopenharmony_ci // 返回服务端确认共享邀请的返回结果 1552e41f4b71Sopenharmony_ci return { 1553e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1554e41f4b71Sopenharmony_ci description: 'confirm invitation succeeded', 1555e41f4b71Sopenharmony_ci value: 'sharing_resource_test' 1556e41f4b71Sopenharmony_ci } 1557e41f4b71Sopenharmony_ci } 1558e41f4b71Sopenharmony_ci // ... 1559e41f4b71Sopenharmony_ci} 1560e41f4b71Sopenharmony_ci``` 1561e41f4b71Sopenharmony_ci 1562e41f4b71Sopenharmony_ci### changeConfirmation 1563e41f4b71Sopenharmony_ci 1564e41f4b71Sopenharmony_cichangeConfirmation(userId: number, bundleName: string, sharingResource: string, state: cloudData.sharing.State): Promise<Result<void>> 1565e41f4b71Sopenharmony_ci 1566e41f4b71Sopenharmony_ci更改端云共享邀请。更改共享邀请时,会指定当前更改共享邀请的应用、共享数据的的共享资源标识以及更改的状态,使用Promise异步回调。 1567e41f4b71Sopenharmony_ci 1568e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.DistributedDataManager.CloudSync.Server 1569e41f4b71Sopenharmony_ci 1570e41f4b71Sopenharmony_ci**参数:** 1571e41f4b71Sopenharmony_ci 1572e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1573e41f4b71Sopenharmony_ci| ------- | ----------------------- | ---- | ----------------------------------------------- | 1574e41f4b71Sopenharmony_ci| userId | number | 是 | 表示用户ID。 | 1575e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用包名。 | 1576e41f4b71Sopenharmony_ci| sharingResource | string | 是 | 端云共享资源标识。 | 1577e41f4b71Sopenharmony_ci| state | [cloudData.sharing.State](js-apis-data-cloudData-sys.md#state11) | 是 | 共享邀请的更改状态。 | 1578e41f4b71Sopenharmony_ci 1579e41f4b71Sopenharmony_ci**返回值:** 1580e41f4b71Sopenharmony_ci 1581e41f4b71Sopenharmony_ci| 类型 | 说明 | 1582e41f4b71Sopenharmony_ci| ------------------- | ------------------------- | 1583e41f4b71Sopenharmony_ci| Promise<[Result](#resultt)<void>> | Promise对象,返回更改共享邀请的结果。 | 1584e41f4b71Sopenharmony_ci 1585e41f4b71Sopenharmony_ci**示例:** 1586e41f4b71Sopenharmony_ci 1587e41f4b71Sopenharmony_ci```ts 1588e41f4b71Sopenharmony_ciimport { cloudData } from '@kit.ArkData'; 1589e41f4b71Sopenharmony_ci 1590e41f4b71Sopenharmony_ciexport default class MyShareCenter implements cloudExtension.ShareCenter { 1591e41f4b71Sopenharmony_ci constructor() {} 1592e41f4b71Sopenharmony_ci async changeConfirmation(userId: number, bundleName: string, sharingResource: string, state: cloudData.sharing.State): 1593e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<void>> { 1594e41f4b71Sopenharmony_ci console.info(`change confirm, bundle: ${bundleName}`); 1595e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得更改共享邀请的返回值 1596e41f4b71Sopenharmony_ci // ... 1597e41f4b71Sopenharmony_ci // 返回服务端更改共享邀请的返回结果 1598e41f4b71Sopenharmony_ci return { 1599e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1600e41f4b71Sopenharmony_ci description: 'change confirm succeeded' 1601e41f4b71Sopenharmony_ci } 1602e41f4b71Sopenharmony_ci } 1603e41f4b71Sopenharmony_ci // ... 1604e41f4b71Sopenharmony_ci} 1605e41f4b71Sopenharmony_ci``` 1606e41f4b71Sopenharmony_ci## 完整示例 1607e41f4b71Sopenharmony_ci 1608e41f4b71Sopenharmony_ci以上示例中的类均采用implements实现,示例代码不能单独编译,需要实现父类中的所有方法才能使用,提供完整示例以作参考。 1609e41f4b71Sopenharmony_ci 1610e41f4b71Sopenharmony_ci```ts 1611e41f4b71Sopenharmony_ciimport { Want, ServiceExtensionAbility } from '@kit.AbilityKit'; 1612e41f4b71Sopenharmony_ciimport { rpc } from '@kit.IPCKit'; 1613e41f4b71Sopenharmony_ciimport { cloudData, cloudExtension } from '@kit.ArkData'; 1614e41f4b71Sopenharmony_ci 1615e41f4b71Sopenharmony_citype Participant = cloudData.sharing.Participant; 1616e41f4b71Sopenharmony_cilet test_lockId: number = 1; 1617e41f4b71Sopenharmony_cilet test_time: number = 10; 1618e41f4b71Sopenharmony_cilet test_space: number = 100; 1619e41f4b71Sopenharmony_cilet test_userId: number = 1; 1620e41f4b71Sopenharmony_ci 1621e41f4b71Sopenharmony_ciclass MyCloudDB implements cloudExtension.CloudDB { 1622e41f4b71Sopenharmony_ci async generateId(count: number): Promise<cloudExtension.Result<Array<string>>> { 1623e41f4b71Sopenharmony_ci console.info(`generate id, count: ${count}`); 1624e41f4b71Sopenharmony_ci let result = new Array<string>(); 1625e41f4b71Sopenharmony_ci // ... 1626e41f4b71Sopenharmony_ci // 返回创建Id的结果 1627e41f4b71Sopenharmony_ci return { 1628e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 1629e41f4b71Sopenharmony_ci description: 'generateId succeeded', 1630e41f4b71Sopenharmony_ci value: result 1631e41f4b71Sopenharmony_ci }; 1632e41f4b71Sopenharmony_ci } 1633e41f4b71Sopenharmony_ci 1634e41f4b71Sopenharmony_ci async update(table: string, values: Array<Record<string, cloudExtension.CloudType>>, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 1635e41f4b71Sopenharmony_ci console.info(`update, table: ${table}`); 1636e41f4b71Sopenharmony_ci let updateRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 1637e41f4b71Sopenharmony_ci // ... 1638e41f4b71Sopenharmony_ci // 返回更新数据的结果 1639e41f4b71Sopenharmony_ci return updateRes; 1640e41f4b71Sopenharmony_ci } 1641e41f4b71Sopenharmony_ci 1642e41f4b71Sopenharmony_ci async insert(table: string, values: Array<Record<string, cloudExtension.CloudType>>, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 1643e41f4b71Sopenharmony_ci console.info(`insert, table: ${table}`); 1644e41f4b71Sopenharmony_ci let insertRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 1645e41f4b71Sopenharmony_ci // ... 1646e41f4b71Sopenharmony_ci // 返回插入数据的结果 1647e41f4b71Sopenharmony_ci return insertRes; 1648e41f4b71Sopenharmony_ci } 1649e41f4b71Sopenharmony_ci 1650e41f4b71Sopenharmony_ci async delete(table: string, extensions: Array<Record<string, cloudExtension.CloudType>>): Promise<Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>>> { 1651e41f4b71Sopenharmony_ci console.info(`delete, table: ${table}`); 1652e41f4b71Sopenharmony_ci let deleteRes: Array<cloudExtension.Result<Record<string, cloudExtension.CloudType>>> = []; 1653e41f4b71Sopenharmony_ci // ... 1654e41f4b71Sopenharmony_ci // 返回插入数据的结果 1655e41f4b71Sopenharmony_ci return deleteRes; 1656e41f4b71Sopenharmony_ci } 1657e41f4b71Sopenharmony_ci 1658e41f4b71Sopenharmony_ci async query(table: string, fields: Array<string>, queryCount: number, queryCursor: string): Promise<cloudExtension.Result<cloudExtension.CloudData>> { 1659e41f4b71Sopenharmony_ci console.info(`query, table: ${table}`); 1660e41f4b71Sopenharmony_ci // ... 1661e41f4b71Sopenharmony_ci // 返回插入数据的结果 1662e41f4b71Sopenharmony_ci return { 1663e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 1664e41f4b71Sopenharmony_ci description: 'query succeeded', 1665e41f4b71Sopenharmony_ci value: { 1666e41f4b71Sopenharmony_ci nextCursor: "test_nextCursor", 1667e41f4b71Sopenharmony_ci hasMore: true, 1668e41f4b71Sopenharmony_ci values: [] 1669e41f4b71Sopenharmony_ci } 1670e41f4b71Sopenharmony_ci }; 1671e41f4b71Sopenharmony_ci } 1672e41f4b71Sopenharmony_ci 1673e41f4b71Sopenharmony_ci async lock(): Promise<cloudExtension.Result<cloudExtension.LockInfo>> { 1674e41f4b71Sopenharmony_ci console.info(`DB lock`); 1675e41f4b71Sopenharmony_ci // ... 1676e41f4b71Sopenharmony_ci // 返回插入数据的结果 1677e41f4b71Sopenharmony_ci return { 1678e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 1679e41f4b71Sopenharmony_ci description: 'lock succeeded', 1680e41f4b71Sopenharmony_ci value: { 1681e41f4b71Sopenharmony_ci interval: test_time, 1682e41f4b71Sopenharmony_ci lockId: test_lockId 1683e41f4b71Sopenharmony_ci } 1684e41f4b71Sopenharmony_ci }; 1685e41f4b71Sopenharmony_ci } 1686e41f4b71Sopenharmony_ci 1687e41f4b71Sopenharmony_ci async heartbeat(lockId: number): Promise<cloudExtension.Result<cloudExtension.LockInfo>> { 1688e41f4b71Sopenharmony_ci console.info(`heartbeat lock`); 1689e41f4b71Sopenharmony_ci // ... 1690e41f4b71Sopenharmony_ci // 返回插入数据的结果 1691e41f4b71Sopenharmony_ci return { 1692e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 1693e41f4b71Sopenharmony_ci description: 'heartbeat succeeded', 1694e41f4b71Sopenharmony_ci value: { 1695e41f4b71Sopenharmony_ci interval: test_time, 1696e41f4b71Sopenharmony_ci lockId: test_lockId 1697e41f4b71Sopenharmony_ci } 1698e41f4b71Sopenharmony_ci }; 1699e41f4b71Sopenharmony_ci } 1700e41f4b71Sopenharmony_ci 1701e41f4b71Sopenharmony_ci async unlock(lockId: number): Promise<cloudExtension.Result<boolean>> { 1702e41f4b71Sopenharmony_ci console.info(`unlock`); 1703e41f4b71Sopenharmony_ci // ... 1704e41f4b71Sopenharmony_ci // 返回插入数据的结果 1705e41f4b71Sopenharmony_ci return { 1706e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 1707e41f4b71Sopenharmony_ci description: 'unlock succeeded', 1708e41f4b71Sopenharmony_ci value: false 1709e41f4b71Sopenharmony_ci }; 1710e41f4b71Sopenharmony_ci } 1711e41f4b71Sopenharmony_ci} 1712e41f4b71Sopenharmony_ci 1713e41f4b71Sopenharmony_ciclass MyAssetLoader implements cloudExtension.AssetLoader { 1714e41f4b71Sopenharmony_ci async download(table: string, gid: string, prefix: string, assets: Array<cloudExtension.CloudAsset>): Promise<Array<cloudExtension.Result<cloudExtension.CloudAsset>>> { 1715e41f4b71Sopenharmony_ci console.info(`download asset loader, table: ${table}, gid: ${gid}, prefix: ${prefix}`); 1716e41f4b71Sopenharmony_ci let downloadRes = Array<cloudExtension.Result<cloudExtension.CloudAsset>>(); 1717e41f4b71Sopenharmony_ci // ... 1718e41f4b71Sopenharmony_ci return downloadRes; 1719e41f4b71Sopenharmony_ci } 1720e41f4b71Sopenharmony_ci 1721e41f4b71Sopenharmony_ci async upload(table: string, gid: string, assets: Array<cloudExtension.CloudAsset>): Promise<Array<cloudExtension.Result<cloudExtension.CloudAsset>>> { 1722e41f4b71Sopenharmony_ci console.info(`upload asset loader, table: ${table}, gid: ${gid}`); 1723e41f4b71Sopenharmony_ci let uploadRes = Array<cloudExtension.Result<cloudExtension.CloudAsset>>(); 1724e41f4b71Sopenharmony_ci // ... 1725e41f4b71Sopenharmony_ci return uploadRes; 1726e41f4b71Sopenharmony_ci } 1727e41f4b71Sopenharmony_ci} 1728e41f4b71Sopenharmony_ci 1729e41f4b71Sopenharmony_ciclass MyShareCenter implements cloudExtension.ShareCenter { 1730e41f4b71Sopenharmony_ci constructor() { 1731e41f4b71Sopenharmony_ci } 1732e41f4b71Sopenharmony_ci 1733e41f4b71Sopenharmony_ci async share(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1734e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1735e41f4b71Sopenharmony_ci console.info(`share, bundle: ${bundleName}`); 1736e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得共享的返回值 1737e41f4b71Sopenharmony_ci // ... 1738e41f4b71Sopenharmony_ci // 返回服务端发起共享的返回结果 1739e41f4b71Sopenharmony_ci let result: Array<cloudExtension.Result<Participant>> = []; 1740e41f4b71Sopenharmony_ci participants.forEach((item => { 1741e41f4b71Sopenharmony_ci result.push({ 1742e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1743e41f4b71Sopenharmony_ci description: 'share succeeded' 1744e41f4b71Sopenharmony_ci }) 1745e41f4b71Sopenharmony_ci })) 1746e41f4b71Sopenharmony_ci return { 1747e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1748e41f4b71Sopenharmony_ci description: 'share succeeded', 1749e41f4b71Sopenharmony_ci value: result 1750e41f4b71Sopenharmony_ci } 1751e41f4b71Sopenharmony_ci } 1752e41f4b71Sopenharmony_ci 1753e41f4b71Sopenharmony_ci async unshare(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1754e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1755e41f4b71Sopenharmony_ci console.info(`unshare, bundle: ${bundleName}`); 1756e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得取消共享的返回值 1757e41f4b71Sopenharmony_ci // ... 1758e41f4b71Sopenharmony_ci // 返回服务端取消共享的返回结果 1759e41f4b71Sopenharmony_ci let result: Array<cloudExtension.Result<Participant>> = []; 1760e41f4b71Sopenharmony_ci participants.forEach((item => { 1761e41f4b71Sopenharmony_ci result.push({ 1762e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1763e41f4b71Sopenharmony_ci description: 'unshare succeeded' 1764e41f4b71Sopenharmony_ci }) 1765e41f4b71Sopenharmony_ci })) 1766e41f4b71Sopenharmony_ci return { 1767e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1768e41f4b71Sopenharmony_ci description: 'unshare succeeded', 1769e41f4b71Sopenharmony_ci value: result 1770e41f4b71Sopenharmony_ci } 1771e41f4b71Sopenharmony_ci } 1772e41f4b71Sopenharmony_ci 1773e41f4b71Sopenharmony_ci async exit(userId: number, bundleName: string, sharingResource: string): 1774e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<void>> { 1775e41f4b71Sopenharmony_ci console.info(`exit share, bundle: ${bundleName}`); 1776e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得退出共享的返回值 1777e41f4b71Sopenharmony_ci // ... 1778e41f4b71Sopenharmony_ci // 返回服务端退出共享的返回结果 1779e41f4b71Sopenharmony_ci return { 1780e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1781e41f4b71Sopenharmony_ci description: 'exit share succeeded' 1782e41f4b71Sopenharmony_ci } 1783e41f4b71Sopenharmony_ci } 1784e41f4b71Sopenharmony_ci 1785e41f4b71Sopenharmony_ci async changePrivilege(userId: number, bundleName: string, sharingResource: string, participants: Array<Participant>): 1786e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<Array<cloudExtension.Result<Participant>>>> { 1787e41f4b71Sopenharmony_ci console.info(`change privilege, bundle: ${bundleName}`); 1788e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得更改权限的返回值 1789e41f4b71Sopenharmony_ci // ... 1790e41f4b71Sopenharmony_ci // 返回服务端更改权限的返回结果 1791e41f4b71Sopenharmony_ci let result: Array<cloudExtension.Result<Participant>> = []; 1792e41f4b71Sopenharmony_ci participants.forEach((item => { 1793e41f4b71Sopenharmony_ci result.push({ 1794e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1795e41f4b71Sopenharmony_ci description: 'change privilege succeeded' 1796e41f4b71Sopenharmony_ci }) 1797e41f4b71Sopenharmony_ci })) 1798e41f4b71Sopenharmony_ci return { 1799e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1800e41f4b71Sopenharmony_ci description: 'change privilege succeeded', 1801e41f4b71Sopenharmony_ci value: result 1802e41f4b71Sopenharmony_ci } 1803e41f4b71Sopenharmony_ci } 1804e41f4b71Sopenharmony_ci 1805e41f4b71Sopenharmony_ci async queryParticipants(userId: number, bundleName: string, sharingResource: string): 1806e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<Array<Participant>>> { 1807e41f4b71Sopenharmony_ci console.info(`query participants, bundle: ${bundleName}`); 1808e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得查询参与者的返回值 1809e41f4b71Sopenharmony_ci // ... 1810e41f4b71Sopenharmony_ci // 返回服务端查询参与者的返回结果 1811e41f4b71Sopenharmony_ci let participants = new Array<cloudData.sharing.Participant>(); 1812e41f4b71Sopenharmony_ci participants.push({ 1813e41f4b71Sopenharmony_ci identity: '000000000', 1814e41f4b71Sopenharmony_ci role: cloudData.sharing.Role.ROLE_INVITEE, 1815e41f4b71Sopenharmony_ci state: cloudData.sharing.State.STATE_ACCEPTED, 1816e41f4b71Sopenharmony_ci privilege: { 1817e41f4b71Sopenharmony_ci writable: false, 1818e41f4b71Sopenharmony_ci readable: true, 1819e41f4b71Sopenharmony_ci creatable: false, 1820e41f4b71Sopenharmony_ci deletable: false, 1821e41f4b71Sopenharmony_ci shareable: false 1822e41f4b71Sopenharmony_ci }, 1823e41f4b71Sopenharmony_ci attachInfo: '' 1824e41f4b71Sopenharmony_ci }) 1825e41f4b71Sopenharmony_ci participants.push({ 1826e41f4b71Sopenharmony_ci identity: '111111111', 1827e41f4b71Sopenharmony_ci role: cloudData.sharing.Role.ROLE_INVITEE, 1828e41f4b71Sopenharmony_ci state: cloudData.sharing.State.STATE_ACCEPTED, 1829e41f4b71Sopenharmony_ci privilege: { 1830e41f4b71Sopenharmony_ci writable: false, 1831e41f4b71Sopenharmony_ci readable: true, 1832e41f4b71Sopenharmony_ci creatable: false, 1833e41f4b71Sopenharmony_ci deletable: false, 1834e41f4b71Sopenharmony_ci shareable: false 1835e41f4b71Sopenharmony_ci }, 1836e41f4b71Sopenharmony_ci attachInfo: '' 1837e41f4b71Sopenharmony_ci }) 1838e41f4b71Sopenharmony_ci return { 1839e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1840e41f4b71Sopenharmony_ci description: 'query participants succeeded', 1841e41f4b71Sopenharmony_ci value: participants 1842e41f4b71Sopenharmony_ci } 1843e41f4b71Sopenharmony_ci } 1844e41f4b71Sopenharmony_ci 1845e41f4b71Sopenharmony_ci async queryParticipantsByInvitation(userId: number, bundleName: string, invitationCode: string): 1846e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<Array<Participant>>> { 1847e41f4b71Sopenharmony_ci console.info(`query participants by invitation, bundle: ${bundleName}`); 1848e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得查询参与者的返回值 1849e41f4b71Sopenharmony_ci // ... 1850e41f4b71Sopenharmony_ci // 返回服务端查询参与者的返回结果 1851e41f4b71Sopenharmony_ci let participants = new Array<cloudData.sharing.Participant>(); 1852e41f4b71Sopenharmony_ci participants.push({ 1853e41f4b71Sopenharmony_ci identity: '000000000', 1854e41f4b71Sopenharmony_ci role: cloudData.sharing.Role.ROLE_INVITEE, 1855e41f4b71Sopenharmony_ci state: cloudData.sharing.State.STATE_ACCEPTED, 1856e41f4b71Sopenharmony_ci privilege: { 1857e41f4b71Sopenharmony_ci writable: false, 1858e41f4b71Sopenharmony_ci readable: true, 1859e41f4b71Sopenharmony_ci creatable: false, 1860e41f4b71Sopenharmony_ci deletable: false, 1861e41f4b71Sopenharmony_ci shareable: false 1862e41f4b71Sopenharmony_ci }, 1863e41f4b71Sopenharmony_ci attachInfo: '' 1864e41f4b71Sopenharmony_ci }) 1865e41f4b71Sopenharmony_ci participants.push({ 1866e41f4b71Sopenharmony_ci identity: '111111111', 1867e41f4b71Sopenharmony_ci role: cloudData.sharing.Role.ROLE_INVITEE, 1868e41f4b71Sopenharmony_ci state: cloudData.sharing.State.STATE_ACCEPTED, 1869e41f4b71Sopenharmony_ci privilege: { 1870e41f4b71Sopenharmony_ci writable: false, 1871e41f4b71Sopenharmony_ci readable: true, 1872e41f4b71Sopenharmony_ci creatable: false, 1873e41f4b71Sopenharmony_ci deletable: false, 1874e41f4b71Sopenharmony_ci shareable: false 1875e41f4b71Sopenharmony_ci }, 1876e41f4b71Sopenharmony_ci attachInfo: '' 1877e41f4b71Sopenharmony_ci }) 1878e41f4b71Sopenharmony_ci return { 1879e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1880e41f4b71Sopenharmony_ci description: 'query participants by invitation succeeded', 1881e41f4b71Sopenharmony_ci value: participants 1882e41f4b71Sopenharmony_ci } 1883e41f4b71Sopenharmony_ci } 1884e41f4b71Sopenharmony_ci 1885e41f4b71Sopenharmony_ci async confirmInvitation(userId: number, bundleName: string, invitationCode: string, state: cloudData.sharing.State): 1886e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<string>> { 1887e41f4b71Sopenharmony_ci console.info(`confirm invitation, bundle: ${bundleName}`); 1888e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得确认共享邀请的返回值 1889e41f4b71Sopenharmony_ci // ... 1890e41f4b71Sopenharmony_ci // 返回服务端确认共享邀请的返回结果 1891e41f4b71Sopenharmony_ci return { 1892e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1893e41f4b71Sopenharmony_ci description: 'confirm invitation succeeded', 1894e41f4b71Sopenharmony_ci value: 'sharing_resource_test' 1895e41f4b71Sopenharmony_ci } 1896e41f4b71Sopenharmony_ci } 1897e41f4b71Sopenharmony_ci 1898e41f4b71Sopenharmony_ci async changeConfirmation(userId: number, bundleName: string, sharingResource: string, state: cloudData.sharing.State): 1899e41f4b71Sopenharmony_ci Promise<cloudExtension.Result<void>> { 1900e41f4b71Sopenharmony_ci console.info(`change confirm, bundle: ${bundleName}`); 1901e41f4b71Sopenharmony_ci // 对接云共享服务端,并获得更改共享邀请的返回值 1902e41f4b71Sopenharmony_ci // ... 1903e41f4b71Sopenharmony_ci // 返回服务端更改共享邀请的返回结果 1904e41f4b71Sopenharmony_ci return { 1905e41f4b71Sopenharmony_ci code: cloudData.sharing.SharingCode.SUCCESS, 1906e41f4b71Sopenharmony_ci description: 'change confirm succeeded' 1907e41f4b71Sopenharmony_ci } 1908e41f4b71Sopenharmony_ci } 1909e41f4b71Sopenharmony_ci} 1910e41f4b71Sopenharmony_ci 1911e41f4b71Sopenharmony_ciclass MyCloudService implements cloudExtension.CloudService { 1912e41f4b71Sopenharmony_ci constructor() { 1913e41f4b71Sopenharmony_ci } 1914e41f4b71Sopenharmony_ci 1915e41f4b71Sopenharmony_ci async getServiceInfo(): Promise<cloudExtension.ServiceInfo> { 1916e41f4b71Sopenharmony_ci console.info(`get service info`); 1917e41f4b71Sopenharmony_ci // ... 1918e41f4b71Sopenharmony_ci return { 1919e41f4b71Sopenharmony_ci enableCloud: true, 1920e41f4b71Sopenharmony_ci id: "test_id", 1921e41f4b71Sopenharmony_ci totalSpace: test_space, 1922e41f4b71Sopenharmony_ci remainingSpace: test_space, 1923e41f4b71Sopenharmony_ci user: test_userId, 1924e41f4b71Sopenharmony_ci }; 1925e41f4b71Sopenharmony_ci } 1926e41f4b71Sopenharmony_ci 1927e41f4b71Sopenharmony_ci async getAppBriefInfo(): Promise<Record<string, cloudExtension.AppBriefInfo>> { 1928e41f4b71Sopenharmony_ci console.info(`get app brief info`); 1929e41f4b71Sopenharmony_ci // ... 1930e41f4b71Sopenharmony_ci return { 1931e41f4b71Sopenharmony_ci "test_bundle": 1932e41f4b71Sopenharmony_ci { 1933e41f4b71Sopenharmony_ci appId: "test_appID", 1934e41f4b71Sopenharmony_ci bundleName: "test_bundlename", 1935e41f4b71Sopenharmony_ci cloudSwitch: true, 1936e41f4b71Sopenharmony_ci instanceId: 0, 1937e41f4b71Sopenharmony_ci } 1938e41f4b71Sopenharmony_ci }; 1939e41f4b71Sopenharmony_ci } 1940e41f4b71Sopenharmony_ci 1941e41f4b71Sopenharmony_ci async getAppSchema(bundleName: string): Promise<cloudExtension.Result<cloudExtension.AppSchema>> { 1942e41f4b71Sopenharmony_ci console.info(`get app schema, bundleName:${bundleName}`); 1943e41f4b71Sopenharmony_ci // ... 1944e41f4b71Sopenharmony_ci return { 1945e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 1946e41f4b71Sopenharmony_ci description: "get app schema success", 1947e41f4b71Sopenharmony_ci value: { 1948e41f4b71Sopenharmony_ci bundleName: "test_bundleName", 1949e41f4b71Sopenharmony_ci version: 1, 1950e41f4b71Sopenharmony_ci databases: [] 1951e41f4b71Sopenharmony_ci } 1952e41f4b71Sopenharmony_ci }; 1953e41f4b71Sopenharmony_ci } 1954e41f4b71Sopenharmony_ci 1955e41f4b71Sopenharmony_ci async subscribe(subInfo: Record<string, Array<cloudExtension.Database>>, expirationTime: number): Promise<cloudExtension.Result<cloudExtension.SubscribeInfo>> { 1956e41f4b71Sopenharmony_ci console.info 1957e41f4b71Sopenharmony_ci (`subscribe expirationTime: ${expirationTime}`); 1958e41f4b71Sopenharmony_ci // ... 1959e41f4b71Sopenharmony_ci return { 1960e41f4b71Sopenharmony_ci code: cloudExtension.ErrorCode.SUCCESS, 1961e41f4b71Sopenharmony_ci description: "subscribe success", 1962e41f4b71Sopenharmony_ci value: { 1963e41f4b71Sopenharmony_ci expirationTime: test_time, 1964e41f4b71Sopenharmony_ci subscribe: {} 1965e41f4b71Sopenharmony_ci } 1966e41f4b71Sopenharmony_ci }; 1967e41f4b71Sopenharmony_ci } 1968e41f4b71Sopenharmony_ci 1969e41f4b71Sopenharmony_ci async unsubscribe(unsubscribeInfo: Record<string, Array<string>>): Promise<number> { 1970e41f4b71Sopenharmony_ci console.info(`unsubscribe`); 1971e41f4b71Sopenharmony_ci // ... 1972e41f4b71Sopenharmony_ci return cloudExtension.ErrorCode.SUCCESS; 1973e41f4b71Sopenharmony_ci } 1974e41f4b71Sopenharmony_ci 1975e41f4b71Sopenharmony_ci async connectDB(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 1976e41f4b71Sopenharmony_ci console.info(`connect DB, bundleName: ${bundleName}`); 1977e41f4b71Sopenharmony_ci return cloudExtension.createCloudDBStub(new MyCloudDB()); 1978e41f4b71Sopenharmony_ci } 1979e41f4b71Sopenharmony_ci 1980e41f4b71Sopenharmony_ci async connectAssetLoader(bundleName: string, database: cloudExtension.Database): Promise<rpc.RemoteObject> { 1981e41f4b71Sopenharmony_ci console.info(`connect asset loader, bundle: ${bundleName}`); 1982e41f4b71Sopenharmony_ci return cloudExtension.createAssetLoaderStub(new MyAssetLoader()); 1983e41f4b71Sopenharmony_ci } 1984e41f4b71Sopenharmony_ci 1985e41f4b71Sopenharmony_ci async connectShareCenter(userId: number, bundleName: string): Promise<rpc.RemoteObject> { 1986e41f4b71Sopenharmony_ci console.info(`connect share center, bundle: ${bundleName}`); 1987e41f4b71Sopenharmony_ci // ... 1988e41f4b71Sopenharmony_ci return cloudExtension.createShareServiceStub(new MyShareCenter()); 1989e41f4b71Sopenharmony_ci } 1990e41f4b71Sopenharmony_ci} 1991e41f4b71Sopenharmony_ci 1992e41f4b71Sopenharmony_ciexport default class MyServiceExtension extends ServiceExtensionAbility { 1993e41f4b71Sopenharmony_ci onCreate(want: Want) { 1994e41f4b71Sopenharmony_ci console.info(`onCreate: ${want}`); 1995e41f4b71Sopenharmony_ci } 1996e41f4b71Sopenharmony_ci 1997e41f4b71Sopenharmony_ci onRequest(want: Want, startId: number) { 1998e41f4b71Sopenharmony_ci console.info(`onRequest: ${want} ${startId}`); 1999e41f4b71Sopenharmony_ci } 2000e41f4b71Sopenharmony_ci 2001e41f4b71Sopenharmony_ci onConnect(want: Want): rpc.RemoteObject | Promise<rpc.RemoteObject> { 2002e41f4b71Sopenharmony_ci console.info(`onConnect: ${want}`); 2003e41f4b71Sopenharmony_ci return cloudExtension.createCloudServiceStub(new MyCloudService()); 2004e41f4b71Sopenharmony_ci } 2005e41f4b71Sopenharmony_ci 2006e41f4b71Sopenharmony_ci onDisconnect(want: Want) { 2007e41f4b71Sopenharmony_ci console.info(`onDisconnect: ${want}`); 2008e41f4b71Sopenharmony_ci } 2009e41f4b71Sopenharmony_ci 2010e41f4b71Sopenharmony_ci onDestroy() { 2011e41f4b71Sopenharmony_ci console.info('onDestroy'); 2012e41f4b71Sopenharmony_ci } 2013e41f4b71Sopenharmony_ci} 2014e41f4b71Sopenharmony_ci``` 2015e41f4b71Sopenharmony_ci<!--no_check--> 2016