1# @ohos.data.cloudData (Device-Cloud Service)
2
3The **cloudData** module provides APIs for implementing device-cloud synergy and device-cloud sharing, and setting the device-cloud sync strategy.
4
5Device-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.
6This module also provides the capability of setting the device-cloud sync strategy.
7
8> **NOTE**
9>
10> 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.
11
12## Modules to Import
13
14```ts
15import { cloudData } from '@kit.ArkData';
16```
17
18## StrategyType
19
20Enumerates the types of the cloud-device sync strategy.
21
22**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client
23
24| Name     | Value | Description       |
25| --------- |---|-----------|
26| NETWORK | 0 | Sync over the network. |
27
28## NetWorkStrategy
29
30Enumerates the network sync options.
31
32**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client
33
34| Name     | Value | Description       |
35| --------- |---|-----------|
36| WIFI | 1 | Sync over Wi-Fi. |
37| CELLULAR | 2 | Sync over the cellular network.  |
38
39## cloudData.setCloudStrategy
40setCloudStrategy(strategy: StrategyType, param?: Array<commonType.ValueType>): Promise<void>
41
42<!--RP1-->
43Sets the device-cloud sync strategy for the application. If no strategy is set, the global strategy set by [setGlobalCloudStrategy<sup>12+</sup>](js-apis-data-cloudData-sys.md#setglobalcloudstrategy12) 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.<!--RP1End-->
44
45**System capability**: SystemCapability.DistributedDataManager.CloudSync.Client
46
47| Name    | Type                                                                         | Mandatory | Description                            |
48| ---------- |-----------------------------------------------------------------------------| ---- | -------------------------------- |
49| strategy  | [StrategyType](#strategytype)                                               | Yes  | Type of the strategy to set.            |
50| param | Array&lt;[commonType.ValueType](js-apis-data-commonType.md#valuetype)&gt; | No  | Strategy parameters to set. If this parameter is not specified, all the configuration is canceled. |
51
52**Return value**
53
54| Type               | Description                     |
55| ------------------- | ------------------------- |
56| Promise&lt;void&gt; | Promise that returns no value. |
57
58**Error codes**
59
60For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
61
62| **ID** | **Error Message**                                                |
63|-----------| ------------------------------------------------------------ |
64| 401       | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
65| 801       | Capability not supported.|
66
67**Example**
68
69```ts
70import { BusinessError } from '@kit.BasicServicesKit';
71
72// Sync data over Wi-Fi only.
73cloudData.setCloudStrategy(cloudData.StrategyType.NETWORK, [cloudData.NetWorkStrategy.WIFI]).then(() => {
74    console.info('Succeeded in setting the cloud strategy');
75}).catch((err: BusinessError) => {
76    console.error(`Failed to set cloud strategy. Code: ${err.code}, message: ${err.message}`);
77});
78
79```
80<!--no_check-->
81