openharmony 鸿蒙 js-apis-data-cloudData

2025-06-12 浏览 (1)

@ohos.data.cloudData (Device-Cloud Service)

The cloudData module provides APIs for implementing device-cloud synergy and device-cloud sharing, and setting the device-cloud sync strategy.

Device-cloud synergy enables sync of the structured data (in RDB stores) between devices and the cloud. The cloud serves as a data hub to implement data backup in the cloud and data consistency between the devices with the same account. This module also provides the capability of setting the device-cloud sync strategy.

NOTE

  • The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import { cloudData } from '@kit.ArkData';

StrategyType

Enumerates the types of the cloud-device sync strategy.

System capability: SystemCapability.DistributedDataManager.CloudSync.Client

NameValueDescription
NETWORK0Sync over the network.

NetWorkStrategy

Enumerates the network sync options.

System capability: SystemCapability.DistributedDataManager.CloudSync.Client

NameValueDescription
WIFI1Sync over Wi-Fi.
CELLULAR2Sync over the cellular network.

cloudData.setCloudStrategy

setCloudStrategy(strategy: StrategyType, param?: Array<commonType.ValueType>): Promise<void>

Sets the device-cloud sync strategy for the application. If no strategy is set, the global strategy set by setGlobalCloudStrategy is used. If the global strategy is not set, the application data is synced over Wi-Fi and the cellular network by default. This API uses a promise to return the result.

System capability: SystemCapability.DistributedDataManager.CloudSync.Client

NameTypeMandatoryDescription
strategyStrategyTypeYesType of the strategy to set.
paramArray<commonType.ValueType>NoStrategy parameters to set. If this parameter is not specified, all the configuration is canceled.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes.

IDError Message
401Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed.
801Capability not supported.

Example

import { BusinessError } from '@kit.BasicServicesKit';

// Sync data over Wi-Fi only.
cloudData.setCloudStrategy(cloudData.StrategyType.NETWORK, [cloudData.NetWorkStrategy.WIFI]).then(() => {
    console.info('Succeeded in setting the cloud strategy');
}).catch((err: BusinessError) => {
    console.error(`Failed to set cloud strategy. Code: ${err.code}, message: ${err.message}`);
});

你可能感兴趣的鸿蒙文章

harmony 鸿蒙ArkData (ArkData Management)

harmony 鸿蒙Data

harmony 鸿蒙OH_Cursor

harmony 鸿蒙OH_Predicates

harmony 鸿蒙OH_Rdb_Config

harmony 鸿蒙OH_Rdb_Store

harmony 鸿蒙OH_VBucket

harmony 鸿蒙OH_VObject

harmony 鸿蒙Preferences

harmony 鸿蒙_r_d_b

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/cwjyvb