diff --git a/en/application-dev/reference/apis/js-apis-cardEmulation.md b/en/application-dev/reference/apis/js-apis-cardEmulation.md index bd1a79344869a57653984122a12da3826ee98327..b306ac2ed56747cae1d6924706cc97815bd20c93 100644 --- a/en/application-dev/reference/apis/js-apis-cardEmulation.md +++ b/en/application-dev/reference/apis/js-apis-cardEmulation.md @@ -16,31 +16,37 @@ import cardEmulation from '@ohos.nfc.cardEmulation'; Enumerates the NFC card emulation types. +> **NOTE** +> This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [hasHceCapability](#hashcecapability9). + **System capability**: SystemCapability.Communication.NFC.CardEmulation | Name| Value| Description| | -------- | -------- | -------- | | HCE | 0 | HCE.| | UICC | 1 | Subscriber identity module (SIM) card emulation.| -| ESE | 2 | embedded Secure Element (eSE) emulation.| +| ESE | 2 | embedded Secure Element (eSE) emulation.| -## CardType +## CardType9+ -Enumerates the card emulation application types. +Enumerates the types of services used by the card emulation application. **System capability**: SystemCapability.Communication.NFC.CardEmulation | Name| Value| Description| | -------- | -------- | -------- | | PAYMENT | "payment" | Payment type.| -| OTHER | "other" | Other types. | +| OTHER | "other" | Other types.| -## cardEmulation.isSupported +## isSupported isSupported(feature: number): boolean Checks whether a certain type of card emulation is supported. +> **NOTE** +> This parameter is supported since API version 6 and deprecated since API version 9. You are advised to use [hasHceCapability](#hashcecapability9). + **System capability**: SystemCapability.Communication.NFC.CardEmulation **Parameters** @@ -55,89 +61,44 @@ Checks whether a certain type of card emulation is supported. | -------- | -------- | | boolean | Returns **true** if the card emulation type is supported; returns **false** otherwise.| -## cardEmulation.isDefaultService +## hasHceCapability9+ -isDefaultService(elementName: ElementName, type: CardType): boolean +hasHceCapability(): boolean -Checks whether the specified application is of the default payment type. +Checks whether HCE is supported. **System capability**: SystemCapability.Communication.NFC.CardEmulation -**Parameters** - -| Name | Type | Mandatory| Description | -| ------- | -------- | ---- | ----------------------- | -| elementName | [ElementName](js-apis-bundleManager-elementName.md#elementname) | Yes| Application description, which includes the bundle name and component name.| -| type | [CardType](#cardtype) | Yes| Application description, which includes the bundle name and component name.| +**Required permissions**: ohos.permission.NFC_CARD_EMULATION **Return value** | **Type**| **Description**| | -------- | -------- | -| boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.| - -## HceService8+ +| boolean | Returns **true** if HCE is supported; returns **false** otherwise.| -Implements HCE, including receiving Application Protocol Data Units (APDUs) from the peer card reader and sending a response. Before using HCE-related APIs, check whether the device supports HCE. +## isDefaultService9+ -### startHCE8+ +isDefaultService(elementName: ElementName, type: CardType): boolean -startHCE(aidList: string[]): boolean +Checks whether an application is the default application of the specified service type. -Starts HCE, including setting the application to be foreground preferred and dynamically registering the application identifier (AID) list. +**System capability**: SystemCapability.Communication.NFC.CardEmulation **Required permissions**: ohos.permission.NFC_CARD_EMULATION -**System capability**: SystemCapability.Communication.NFC.CardEmulation - **Parameters** | Name | Type | Mandatory| Description | | ------- | -------- | ---- | ----------------------- | -| aidList | string[] | Yes | AID list to register.| - -### stopHCE8+ - -stopHCE(): boolean - -Stops HCE, including removing the foreground preferred attribute and releasing the dynamically registered AID list. - -**Required permissions**: ohos.permission.NFC_CARD_EMULATION - -**System capability**: SystemCapability.Communication.NFC.CardEmulation - -### on8+ - -on(type: "hceCmd", callback: AsyncCallback): void; +| elementName | [ElementName](js-apis-bundleManager-elementName.md#elementname) | Yes| Application description, which consists of the bundle name and component name.| +| type | [CardType](#cardtype9) | Yes| Card emulation service type.| -Registers a callback to receive APDUs from the peer card reader. - -**Required permissions**: ohos.permission.NFC_CARD_EMULATION - -**System capability**: SystemCapability.Communication.NFC.CardEmulation - -**Parameters** - -| Name | Type | Mandatory| Description | -| -------- | ----------------------- | ---- | -------------------------------------------- | -| type | string | Yes | Event type to subscribe to. The value is **hceCmd**. | -| callback | AsyncCallback | Yes | Callback invoked to return the APDU, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| - -### sendResponse8+ - -sendResponse(responseApdu: number[]): void; - -Sends a response to the peer card reader. - -**Required permissions**: ohos.permission.NFC_CARD_EMULATION - -**System capability**: SystemCapability.Communication.NFC.CardEmulation - -**Parameters** +**Return value** -| Name | Type | Mandatory| Description | -| ------------ | -------- | ---- | -------------------------------------------------- | -| responseApdu | number[] | Yes | Response APDU sent to the peer card reader. The value consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| +| **Type**| **Description**| +| -------- | -------- | +| boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.| **Example** @@ -150,30 +111,16 @@ if (!isHceSupported) { return; } +var hasHceCap = cardEmulation.hasHceCapability(); +if (!hasHceCap) { + console.log('this device hasHceCapability false, ignore it.'); + return; +} + var elementName = { "bundleName": "com.test.cardemulation", "abilityName": "com.test.cardemulation.MainAbility", }; var isDefaultService = cardEmulation.isDefaultService(elementName, cardEmulation.CardType.PAYMENT); console.log('is the app is default service for this card type: ' + isDefaultService); - -// The device supports HCE and transimits APDUs with the remote NFC reader. -var hceService = new cardEmulation.HceService(); -hceService.startHCE([ - "F0010203040506", "A0000000041010" -]); - -hceService.on("hceCmd", (err, res) => { - if(err.data === 0) { - console.log('callback => Operation hceCmd succeeded. Data: ' + JSON.stringify(res)); - hceService.sendResponse([0x00,0xa4,0x04,0x00, - 0x0e,0x32,0x50,0x41,0x59,0x2e,0x53,0x59,0x53,0x2e,0x44,0x44, - 0x46,0x30,0x31,0x00]); - } else { - console.log('callback => Operation hceCmd failed. Cause: ' + err.data); - } -}) - -// stop HCE when the application exit the nfc card emulation. -hceService.stopHCE(); ``` diff --git a/en/application-dev/reference/apis/js-apis-cert.md b/en/application-dev/reference/apis/js-apis-cert.md index cf334f6fd36fd654c2c9558865b0c9f06b68d9ef..fa3aa58c0907c2eb941f4b7485c59e659c99e692 100644 --- a/en/application-dev/reference/apis/js-apis-cert.md +++ b/en/application-dev/reference/apis/js-apis-cert.md @@ -104,6 +104,11 @@ Creates an **X509Cert** instance. This API uses an asynchronous callback to retu | inStream | [EncodingBlob](#encodingblob) | Yes | X.509 certificate serialization data. | | callback | AsyncCallback\ | Yes | Callback invoked to return the result. **X509Cert** instance created.| +**Error codes** + +| ID| Error Message | +| -------- | ------------- | +| 19020001 | Memory error. | **Example** @@ -146,6 +151,12 @@ Creates an **X509Cert** instance. This API uses a promise to return the result. | ------- | ---------------- | | Promise\ | **X509Cert** instance created.| +**Error codes** + +| ID| Error Message | +| -------- | ------------- | +| 19020001 | Memory error. | + **Example** ```js @@ -184,6 +195,11 @@ Verifies the certificate signature. This API uses an asynchronous callback to re | key | cryptoFramework.PubKey | Yes | Public key used for signature verification. | | callback | AsyncCallback\ | Yes | Callback invoked to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------ | +| 19030001 | Crypto operation error. | **Example** @@ -235,6 +251,12 @@ Verifies the certificate signature. This API uses a promise to return the result | -------------- | ----------- | | Promise\ | Promise used to return the result.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------ | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -275,6 +297,13 @@ Obtains the serialized X.509 certificate data. This API uses an asynchronous cal | -------- | --------------------------------------------- | ---- | -------------------------------- | | callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback invoked to return the result. Promise used to return the serialized X.509 certificate data obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| **Example** @@ -318,6 +347,14 @@ Obtains the serialized X.509 certificate data. This API uses a promise to return | --------------------------------------- | ---------------------- | | Promise\<[EncodingBlob](#encodingblob)> | Promise used to return the serialized X.509 certificate data obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -356,6 +393,13 @@ Obtains the public key of this X.509 certificate. This API uses an asynchronous | ------ | ---------------- | | cryptoFramework.PubKey | Public key of the X509 certificate obtained. This object is used only for **verify()** of **X509Cert**.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -398,6 +442,15 @@ Checks the validity period of this X.509 certificate. This API uses an asynchron | -------- | -------------- | ---- | ---------- | | date | string | Yes | Date in the YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ format. The date must end with **Z**, which indicates the UTC.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19030001 | Crypto operation error.| +| 19030003 | The certificate has not taken effect. | +| 19030004 | The certificate has expired.| + **Example** ```js @@ -513,6 +566,14 @@ Obtains the X.509 certificate issuer. | --------------------- | ---------------------- | | [DataBlob](#datablob) | X.509 certificate issuer obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -549,6 +610,14 @@ Obtains the subject of this X.509 certificate. | --------------------- | -------------------- | | [DataBlob](#datablob) | Subject name obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -585,6 +654,14 @@ Obtains the start time of this X.509 certificate. | ------ | ------------------------------------------------------------ | | string | Start time of the X509 certificate validity period, in the YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ format. The value must end with **Z**, which indicates the UTC.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -621,6 +698,14 @@ Obtains the expiration time of this X.509 certificate. | ------ | ------------------------------------------------------------ | | string | Expiration time of the X509 certificate validity period, in the YYMMDDHHMMSSZ or YYYYMMDDHHMMSSZ format. The value must end with **Z**, which indicates the UTC.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -657,6 +742,14 @@ Obtains the signature data of this X.509 certificate. | --------------------- | -------------------- | | [DataBlob](#datablob) | Signature data obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -693,6 +786,14 @@ Obtains the signing algorithm of this X.509 certificate. | ------ | ------------------------ | | string | X.509 certificate signing algorithm obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -729,6 +830,14 @@ Obtains the object identifier (OID) of the X.509 certificate signing algorithm. | ------ | --------------------------------- | | string | OID obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -765,6 +874,14 @@ Obtains the signing algorithm parameters of this X.509 certificate. | --------------------- | ------------------------ | | [DataBlob](#datablob) | X.509 certificate signing algorithm parameters obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -801,6 +918,13 @@ Obtains the key usage of this X.509 certificate. | --------------------- | -------------------- | | [DataBlob](#datablob) | Key usage of the X.509 certificate obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -837,6 +961,14 @@ Obtains the usage of the extended key of this X.509 certificate. | ----------------------- | ------------------------ | | [DataArray](#dataarray) | Usage of the extended key obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -909,6 +1041,14 @@ Obtains the Subject Alternative Names (SANs) of this X.509 certificate. | ----------------------- | ------------------------ | | [DataArray](#dataarray) | SANs obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -945,6 +1085,14 @@ Obtains the Issuer Alternative Names (IANs) of this X.509 certificate. | ----------------------- | -------------------------- | | [DataArray](#dataarray) | IANs obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error.| + **Example** ```js @@ -982,6 +1130,11 @@ Creates an **X509Crl** instance. This API uses an asynchronous callback to retur | inStream | [EncodingBlob](#encodingblob) | Yes | Serialized certificate revocation list (CRL) data. | | callback | AsyncCallback\ | Yes | Callback invoked to return the result. Promise used to return the **X509Crl** instance created.| +**Error codes** + +| ID| Error Message | +| -------- | ------------- | +| 19020001 | Memory error. | **Example** @@ -1024,6 +1177,12 @@ Creates an **X509Crl** instance. This API uses a promise to return the result. | ----------------- | -------------------- | | Promise\ | Promise used to return the **X509Crl** instance created.| +**Error codes** + +| ID| Error Message | +| -------- | ------------- | +| 19020001 | Memory error. | + **Example** ```js @@ -1145,6 +1304,13 @@ Obtains the serialized X.509 CRL data. This API uses an asynchronous callback to | -------- | ---------------------------- | ---- | ------------------------------------------ | | callback | AsyncCallback\ | Yes | Callback invoked to return the serialized X.509 CRL data obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | **Example** @@ -1188,6 +1354,14 @@ Obtains the serialized X.509 CRL data. This API uses a promise to return the res | ---------------------- | -------------------------------- | | Promise\ | Promise used to return the serialized X.509 CRL data obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1227,6 +1401,11 @@ Verifies the signature of the X.509 CRL. This API uses an asynchronous callback | key | cryptoFramework.PubKey | Yes | Public key used for signature verification. | | callback | AsyncCallback\ | Yes | Callback invoked to return the result. If **error** is **null**, the signature verification is successful. If **error** is not **null**, the signature verification fails.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19030001 | Crypto operation error. | **Example** @@ -1279,6 +1458,12 @@ Verifies the signature of the X.509 CRL. This API uses a promise to return the r | ---- | ------------------------------------------------------------ | | Promise\ | Promise used to return the result.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1356,6 +1541,14 @@ Obtains the issuer of the X.509 CRL. | --------------------- | ------------------------------ | | [DataBlob](#datablob) | Issuer of the X.509 CRL obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1392,6 +1585,14 @@ Obtains the date when the X.509 CRL was last updated. | ------ | ------------------------------------ | | string | Last update date of the X.509 CRL.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1428,6 +1629,14 @@ Obtains the date when the CRL will be updated the next time. | ------ | ------------------------------------ | | string | Next update date obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1470,6 +1679,13 @@ Obtains the revoked X.509 certificate based on the specified serial number of th | ---------------------- | --------------------- | | X509CrlEntry | Promise used to return the revoked X.509 certificate obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1518,6 +1734,13 @@ Obtains the revoked X.509 certificate based on the specified certificate. This A | ------------ | -------------------- | | X509CrlEntry | Promise used to return the revoked X.509 certificate obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1560,6 +1783,12 @@ Obtains all the revoked X.509 certificates. This API uses an asynchronous callba | -------- | ----------------------------------- | ---- | -------------------------------- | | callback | AsyncCallback> | Yes | Callback invoked to return the result. Promise used to return a list of revoked X.509 certificates.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19030001 | Crypto operation error. | **Example** @@ -1603,6 +1832,13 @@ Obtains all the revoked X.509 certificates. This API uses a promise to return th | ----------------------------- | ---------------------- | | Promise> | Promise used to return a list of revoked X.509 certificates.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1641,6 +1877,14 @@ Obtains the DER-encoded CRL information, the **tbsCertList** from this CRL. This | --------------------- | ------------------------------- | | [DataBlob](#datablob) | Promise used to return the **tbsCertList** information obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1681,6 +1925,14 @@ Obtains the signature data of the X.509 CRL. | --------------------- | ------------------------------ | | [DataBlob](#datablob) | Signature data of the X.509 CRL obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1717,6 +1969,14 @@ Obtains the signing algorithm of the X.509 CRL. | ------ | -------------------------------- | | string | Signing algorithm obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1753,6 +2013,14 @@ Obtains the OID of the X.509 CRL signing algorithm. OIDs are allocated by the In | ------ | --------------------------------------------- | | string | OID of the X.509 CRL signing algorithm obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1789,6 +2057,14 @@ Obtains the parameters of the X.509 CRL signing algorithm. | --------------------- | ---------------------------------- | | [DataBlob](#datablob) | Algorithm parameters obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1831,6 +2107,14 @@ Creates a **CertChainValidator** object. | ------------------ | -------------------- | | CertChainValidator | **CertChainValidator** object created.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -1846,7 +2130,7 @@ Provides APIs for certificate chain validator operations. ### Attributes -**System capability**: SystemCapability.Security.CryptoFramework +**System capability**: SystemCapability.Security.Cert | Name | Type | Readable| Writable| Description | | ------- | ------ | ---- | ---- | -------------------------- | @@ -1858,7 +2142,7 @@ Provides APIs for certificate chain validator operations. validate(certChain : CertChainData, callback : AsyncCallback\) : void Validates the X.509 certificate chain. This API uses an asynchronous callback to return the result. -The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details, see [Certificate Specifications](../../security/cert-overview.md#certificate-specifications). +The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details, see [Certificate Specifications](./../security/cert-overview.md#certificate-specifications). **System capability**: SystemCapability.Security.Cert @@ -1869,6 +2153,19 @@ The certificate chain validator does not verify the certificate validity period | certChain | [CertChainData](#certchaindata) | Yes | Serialized X.509 certificate chain data. | | callback | AsyncCallback\ | Yes | Callback invoked to return the result. If **error** is **null**, the X.509 certificate chain is valid. If **error** is not **null**, the X.509 certificate chain is not valid.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | +| 19030002 | The certificate signature verification failed. | +| 19030003 | The certificate has not taken effect. | +| 19030004 | The certificate has expired. | +| 19030005 | Failed to obtain the certificate issuer. | +| 19030006 | The key cannot be used for signing a certificate. | +| 19030007 | The key cannot be used for digital signature. | **Example** @@ -1900,7 +2197,7 @@ validator.validate(certChainData, function (error, data) { validate(certChain : CertChainData) : Promise\ Validates the X.509 certificate chain. This API uses a promise to return the result. -The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details, see [Certificate Specifications](../../security/cert-overview.md#certificate-specifications). +The certificate chain validator does not verify the certificate validity period because the system time on the device is untrusted. To check the validity period of a certificate, use the [checkValidityWithDate()](#checkvaliditywithdate) API of the **X509Cert** class. For details, see [Certificate Specifications](./../security/cert-overview.md#certificate-specifications). **System capability**: SystemCapability.Security.Cert @@ -1916,6 +2213,20 @@ The certificate chain validator does not verify the certificate validity period | -------------- | ----------- | | Promise\ | Promise used to return the result.| +**Error codes** + +| ID| Error Message | +| -------- | ------------------------------------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | +| 19030002 | The certificate signature verification failed. | +| 19030003 | The certificate has not taken effect. | +| 19030004 | The certificate has expired. | +| 19030005 | Failed to obtain the certificate issuer. | +| 19030006 | The key cannot be used for signing a certificate. | +| 19030007 | The key cannot be used for digital signature. | + **Example** ```js @@ -1980,6 +2291,13 @@ Obtains the serialized data of this revoked certificate. This API uses an asynch | -------- | --------------------------------------------- | ---- | ------------------------------------ | | callback | AsyncCallback\<[EncodingBlob](#encodingblob)> | Yes | Callback invoked to return the result. Promise used to return the serialized data of the revoked certificate obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | **Example** @@ -2011,6 +2329,14 @@ Obtains the serialized data of this revoked certificate. This API uses a promise | --------------------------------------- | -------------------------- | | Promise\<[EncodingBlob](#encodingblob)> | Promise used to return the serialized data of the revoked certificate obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js @@ -2063,6 +2389,13 @@ Obtains the issuer of this revoked certificate. This API uses an asynchronous ca | --------------------- | ----------------------- | | [DataBlob](#datablob) | Promise used to return the issuer of the revoked certificate obtained.| +**Error codes** + +| ID| Error Message | +| -------- | -------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | + **Example** ```js @@ -2091,6 +2424,14 @@ Obtains the date when the certificate was revoked. This API uses an asynchronous | ------ | ------------------ | | string | Promise used to return the certificate revocation date obtained.| +**Error codes** + +| ID| Error Message | +| -------- | ----------------------- | +| 19020001 | Memory error. | +| 19020002 | Runtime error. | +| 19030001 | Crypto operation error. | + **Example** ```js diff --git a/en/application-dev/reference/apis/js-apis-cryptoFramework.md b/en/application-dev/reference/apis/js-apis-cryptoFramework.md index 2e067f3e8ba583137b746e3c0fe0c2770aa9139b..6060ed463fda76643a1c3d04aedefe765ab80a3f 100644 --- a/en/application-dev/reference/apis/js-apis-cryptoFramework.md +++ b/en/application-dev/reference/apis/js-apis-cryptoFramework.md @@ -51,7 +51,7 @@ For details about the supported specifications, see [HMAC Algorithm Specificatio | Name | Type | Mandatory| Description | | ------- | ------ | ---- | ------------------------------------------------------------ | -| algName | string | Yes | Digest algorithm. For details about the supported algorithms, see [HMAC Algorithm Specifications](../../security/cryptoFramework-overview.md#hmac-algorithm-specifications). | +| algName | string | Yes | Digest algorithm. For details about the supported algorithms, see [HMAC Algorithm Specifications](../../security/cryptoFramework-overview.md#hmac-algorithm-specifications).| **Return value** @@ -483,7 +483,7 @@ For details about the supported specifications, see [MD Algorithm Specifications | Name | Type | Mandatory| Description | | ------- | ------ | ---- | ------------------------------------------------------------ | -| algName | string | Yes | Digest algorithm. For details about the supported algorithms, see [MD Algorithm Specifications](../../security/cryptoFramework-overview.md#md-algorithm-specifications). | +| algName | string | Yes | Digest algorithm. For details about the supported algorithms, see [MD Algorithm Specifications](../../security/cryptoFramework-overview.md#md-algorithm-specifications).| **Return value** @@ -1852,7 +1852,7 @@ Updates the data to encrypt or decrypt by segment. This API uses a promise to re | Type | Description | | ------------------------------- | ------------------------------------------------ | -| Promise\<[DataBlob](#datablob)> | Promise used to return the **DataBlob** (containing the encrypted or decrypted data). | +| Promise\<[DataBlob](#datablob)> | Promise used to return the **DataBlob** (containing the encrypted or decrypted data).| **Error codes** @@ -2267,6 +2267,8 @@ Signs the data. This API uses a promise to return the result. | -------------- | ----------- | | Promise\ | Promise used to return the result.| +**Error codes** + | ID| Error Message | | -------- | ---------------------- | | 17620001 | memory error. | diff --git a/en/application-dev/reference/apis/js-apis-data-relationalStore.md b/en/application-dev/reference/apis/js-apis-data-relationalStore.md index d2afe1626ac0b84e695ce9f3b3d12010c0ff6060..b21433649008567080852a8bbc88562d9f61d75a 100644 --- a/en/application-dev/reference/apis/js-apis-data-relationalStore.md +++ b/en/application-dev/reference/apis/js-apis-data-relationalStore.md @@ -8,7 +8,7 @@ The **relationalStore** module provides the following functions: - [RdbStore](#rdbstore): provides APIs for managing data in an RDB store. - [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store. -> **NOTE**
+> **NOTE** > > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -30,7 +30,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul | Name | Type | Mandatory| Description | | -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | -| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).| | config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | | callback | AsyncCallback<[RdbStore](#rdbstore)> | Yes | Callback invoked to return the RDB store obtained. | @@ -108,7 +108,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set | Name | Type | Mandatory| Description | | ------- | -------------------------------- | ---- | ------------------------------------------------------------ | -| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).| | config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | **Return value** @@ -188,7 +188,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul | Name | Type | Mandatory| Description | | -------- | ------------------------- | ---- | ------------------------------------------------------------ | -| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).| | name | string | Yes | Name of the RDB store to delete. | | callback | AsyncCallback<void> | Yes | Callback invoked to return the result. | @@ -249,7 +249,7 @@ Deletes an RDB store. This API uses a promise to return the result. | Name | Type | Mandatory| Description | | ------- | ------- | ---- | ------------------------------------------------------------ | -| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| +| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).| | name | string | Yes | Name of the RDB store to delete. | **Return value** @@ -363,6 +363,8 @@ Defines the database synchronization mode. Defines the subscription type. +**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC + **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core | Name | Value | Description | @@ -2430,9 +2432,9 @@ Synchronizes data between devices. This API uses a promise to return the result. let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); predicates.inDevices(['12345678abcde']); let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates); -promise.then((resultSet) =>{ +promise.then((result) =>{ console.info(`Sync done.`); - for (let i = 0; i < resultSet.length; i++) { + for (let i = 0; i < result.length; i++) { console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); } }).catch((err) => { @@ -2511,10 +2513,12 @@ Provides APIs to access the result set obtained by querying the RDB store. A res Obtain the **resultSet** object first. ```js +let resultSet = null; let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); predicates.equalTo("AGE", 18); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); -promise.then((resultSet) => { +promise.then((result) => { + resultSet = result; console.info(`resultSet columnNames: ${resultSet.columnNames}`); console.info(`resultSet columnCount: ${resultSet.columnCount}`); }); @@ -2685,7 +2689,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); promise.then((resultSet) => { - resultSet.(5); + resultSet.goToRow(5); resultSet.close(); }).catch((err) => { console.error(`query failed, err: ${err}`); diff --git a/en/application-dev/reference/apis/js-apis-file-fs.md b/en/application-dev/reference/apis/js-apis-file-fs.md index 806f2178ad1017606abfcbdbaa6edeefecbf07b4..748d78b442fd3fefc4180a3f2d9b2bc0dade2500 100644 --- a/en/application-dev/reference/apis/js-apis-file-fs.md +++ b/en/application-dev/reference/apis/js-apis-file-fs.md @@ -5,7 +5,6 @@ The **fs** module provides APIs for file operations, including basic file manage > **NOTE** > > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> > - The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). ## Modules to Import @@ -60,9 +59,9 @@ Obtains detailed file information. This API uses a promise to return the result. **Return value** - | Type | Description | - | ---------------------------- | ---------- | - | Promise<[Stat](#stat)> | Promise used to return the file information obtained.| +| Type | Description | +| ---------------------------- | ---------- | +| Promise<[Stat](#stat)> | Promise used to return the file information obtained.| **Example** @@ -119,9 +118,9 @@ Obtains detailed file information synchronously. **Return value** - | Type | Description | - | ------------- | ---------- | - | [Stat](#stat) | File information obtained.| +| Type | Description | +| ------------- | ---------- | +| [Stat](#stat) | File information obtained.| **Example** @@ -146,9 +145,9 @@ Checks whether a file exists. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<boolean> | Promise used to return a Boolean value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<boolean> | Promise used to return a Boolean value.| **Example** @@ -233,15 +232,15 @@ Closes a file. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | file | [File](#file)\|number | Yes | File object or FD of the file to close.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| file | [File](#file)\|number | Yes | File object or FD of the file to close.| **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -266,10 +265,10 @@ Closes a file. This API uses an asynchronous callback to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ------------ | - | file | [File](#file)\|number | Yes | File object or FD of the file to close.| - | callback | AsyncCallback<void> | Yes | Callback invoked when the file is closed asynchronously.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------ | +| file | [File](#file)\|number | Yes | File object or FD of the file to close.| +| callback | AsyncCallback<void> | Yes | Callback invoked when the file is closed asynchronously.| **Example** @@ -295,9 +294,9 @@ Synchronously closes a file. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | file | [File](#file)\|number | Yes | File object or FD of the file to close.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| file | [File](#file)\|number | Yes | File object or FD of the file to close.| **Example** @@ -317,17 +316,17 @@ Copies a file. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | -------------------------- | ---- | ---------------------------------------- | - | src | string\|number | Yes | Path or FD of the file to copy. | - | dest | string\|number | Yes | Destination path of the file or FD of the file created. | - | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file of the same name.| +| Name | Type | Mandatory | Description | +| ---- | -------------------------- | ---- | ---------------------------------------- | +| src | string\|number | Yes | Path or FD of the file to copy. | +| dest | string\|number | Yes | Destination path of the file or FD of the file created. | +| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file of the same name.| **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -351,12 +350,12 @@ Copies a file. This API uses an asynchronous callback to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | -------- | -------------------------- | ---- | ---------------------------------------- | - | src | string\|number | Yes | Path or FD of the file to copy. | - | dest | string\|number | Yes | Destination path of the file or FD of the file created. | - | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.| - | callback | AsyncCallback<void> | Yes | Callback invoked when the file is copied asynchronously. | +| Name | Type | Mandatory | Description | +| -------- | -------------------------- | ---- | ---------------------------------------- | +| src | string\|number | Yes | Path or FD of the file to copy. | +| dest | string\|number | Yes | Destination path of the file or FD of the file created. | +| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.| +| callback | AsyncCallback<void> | Yes | Callback invoked when the file is copied asynchronously. | **Example** @@ -383,11 +382,11 @@ Synchronously copies a file. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | -------------------------- | ---- | ---------------------------------------- | - | src | string\|number | Yes | Path or FD of the file to copy. | - | dest | string\|number | Yes | Destination path of the file or FD of the file created. | - | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.| +| Name | Type | Mandatory | Description | +| ---- | -------------------------- | ---- | ---------------------------------------- | +| src | string\|number | Yes | Path or FD of the file to copy. | +| dest | string\|number | Yes | Destination path of the file or FD of the file created. | +| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.
**0**: overwrite the file with the same name and truncate the part that is not overwritten.| **Example** @@ -414,9 +413,9 @@ Creates a directory. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -476,7 +475,7 @@ Synchronously creates a directory. **Example** ```js - let dirPath = path + '/testDir'; + let dirPath = pathDir + '/testDir'; fs.mkdirSync(dirPath); ``` @@ -498,9 +497,9 @@ Opens a file. This API uses a promise to return the result. File uniform resourc **Return value** - | Type | Description | - | --------------------- | ----------- | - | Promise<[File](#file)> | Promise used to return the file object.| +| Type | Description | +| --------------------- | ----------- | +| Promise<[File](#file)> | Promise used to return the file object.| **Example** @@ -559,9 +558,9 @@ Synchronously opens a file. File URIs are supported. **Return value** - | Type | Description | - | ------ | ----------- | - | [File](#file) | File object opened.| +| Type | Description | +| ------ | ----------- | +| [File](#file) | File object opened.| **Example** @@ -590,9 +589,9 @@ Reads data from a file. This API uses a promise to return the result. **Return value** - | Type | Description | - | ---------------------------------- | ------ | - | Promise<number> | Promise used to return the data read.| +| Type | Description | +| ---------------------------------- | ------ | +| Promise<number> | Promise used to return the data read.| **Example** @@ -619,12 +618,12 @@ Reads data from a file. This API uses an asynchronous callback to return the res **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ---------------------------------------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | - | options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| - | callback | AsyncCallback<number> | Yes | Callback invoked when the data is read asynchronously. | +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | +| options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| +| callback | AsyncCallback<number> | Yes | Callback invoked when the data is read asynchronously. | **Example** @@ -654,17 +653,17 @@ Synchronously reads data from a file. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | - | options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | +| options | Object | No | The options are as follows:
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| **Return value** - | Type | Description | - | ------ | -------- | - | number | Length of the data read.| +| Type | Description | +| ------ | -------- | +| number | Length of the data read.| **Example** @@ -693,9 +692,9 @@ Deletes a directory. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -776,9 +775,9 @@ Deletes a file. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -853,17 +852,17 @@ Writes data into a file. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ------------------------------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| Name | Type | Mandatory | Description | +| ------- | ------------------------------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| **Return value** - | Type | Description | - | --------------------- | -------- | - | Promise<number> | Promise used to return the length of the data written.| +| Type | Description | +| --------------------- | -------- | +| Promise<number> | Promise used to return the length of the data written.| **Example** @@ -889,12 +888,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| - | callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | **Example** @@ -922,17 +921,17 @@ Synchronously writes data into a file. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ------------------------------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| Name | Type | Mandatory | Description | +| ------- | ------------------------------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| **Return value** - | Type | Description | - | ------ | -------- | - | number | Length of the data written in the file.| +| Type | Description | +| ------ | -------- | +| number | Length of the data written in the file.| **Example** @@ -961,9 +960,9 @@ Truncates a file. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -1050,9 +1049,9 @@ Reads the text content of a file. This API uses a promise to return the result. **Return value** - | Type | Description | - | --------------------- | ---------- | - | Promise<string> | Promise used to return the content read.| +| Type | Description | +| --------------------- | ---------- | +| Promise<string> | Promise used to return the content read.| **Example** @@ -1113,9 +1112,9 @@ Synchronously reads the text of a file. **Return value** - | Type | Description | - | ------ | -------------------- | - | string | Promise used to return the content of the file read.| +| Type | Description | +| ------ | -------------------- | +| string | Promise used to return the content of the file read.| **Example** @@ -1141,9 +1140,9 @@ Obtains information about a symbolic link. This API uses a promise to return the **Return value** - | Type | Description | - | ---------------------------- | ---------- | - | Promise<[Stat](#stat)> | Promise used to return the symbolic link information obtained. For details, see **stat**.| +| Type | Description | +| ---------------------------- | ---------- | +| Promise<[Stat](#stat)> | Promise used to return the symbolic link information obtained. For details, see **stat**.| **Example** @@ -1201,9 +1200,9 @@ Obtains information about a symbolic link synchronously. **Return value** - | Type | Description | - | ------------- | ---------- | - | [Stat](#stat) | File information obtained.| +| Type | Description | +| ------------- | ---------- | +| [Stat](#stat) | File information obtained.| **Example** @@ -1229,9 +1228,9 @@ Renames a file or directory. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -1309,15 +1308,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | fd | number | Yes | FD of the file.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| fd | number | Yes | FD of the file.| **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -1342,10 +1341,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | --------------- | - | fd | number | Yes | FD of the file. | - | Callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | --------------- | +| fd | number | Yes | FD of the file. | +| Callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| **Example** @@ -1373,9 +1372,9 @@ Flushes data of a file to disk synchronously. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | fd | number | Yes | FD of the file.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| fd | number | Yes | FD of the file.| **Example** @@ -1397,15 +1396,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. ** **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | fd | number | Yes | FD of the file.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| fd | number | Yes | FD of the file.| **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -1431,10 +1430,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------------- | ---- | ----------------- | - | fd | number | Yes | FD of the file. | - | callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------------- | ---- | ----------------- | +| fd | number | Yes | FD of the file. | +| callback | AsyncCallback<void> | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| **Example** @@ -1461,9 +1460,9 @@ Synchronizes data in a file synchronously. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ------------ | - | fd | number | Yes | FD of the file.| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ------------ | +| fd | number | Yes | FD of the file.| **Example** @@ -1492,9 +1491,9 @@ Creates a symbolic link based on a file path. This API uses a promise to return **Return value** - | Type | Description | - | ------------------- | ---------------------------- | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ------------------- | ---------------------------- | +| Promise<void> | Promise that returns no value.| **Example** @@ -1574,24 +1573,24 @@ Lists all files in a directory. This API uses a promise to return the result.
{ console.info("listFile succeed"); - for (let i = 0; i < filenames.size; i++) { + for (let i = 0; i < filenames.length; i++) { console.info("fileName: %s", filenames[i]); } }).catch((err) => { @@ -1627,19 +1626,19 @@ Lists all files in a directory. This API uses an asynchronous callback to return **Parameters** - | Name | Type | Mandatory | Description | - | ------ | ------ | ---- | --------------------------- | - | path | string | Yes | Path of the directory in the application sandbox.| - | options | Object | No | File filtering options.| - | callback | AsyncCallback<string[]> | Yes | Callback invoked to return the file names listed. | +| Name | Type | Mandatory | Description | +| ------ | ------ | ---- | --------------------------- | +| path | string | Yes | Path of the directory in the application sandbox.| +| options | Object | No | File filtering options.| +| callback | AsyncCallback<string[]> | Yes | Callback invoked to return the file names listed. | **options parameters** - | Name | Type | Mandatory | Description | - | ------ | ------ | ---- | --------------------------- | - | recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.| - | listNum | number | No | Number of file names to list. The default value **0** means to list all files.| - | filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.| +| Name | Type | Mandatory | Description | +| ------ | ------ | ---- | --------------------------- | +| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.| +| listNum | number | No | Number of file names to list. The default value **0** means to list all files.| +| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.| **Example** @@ -1659,7 +1658,7 @@ Lists all files in a directory. This API uses an asynchronous callback to return console.info("list file failed with error message: " + err.message + ", error code: " + err.code); } else { console.info("listFile succeed"); - for (let i = 0; i < filenames.size; i++) { + for (let i = 0; i < filenames.length; i++) { console.info("filename: %s", filenames[i]); } } @@ -1678,24 +1677,24 @@ Lists all files in a directory synchronously. This API supports recursive listin **Parameters** - | Name | Type | Mandatory | Description | - | ------ | ------ | ---- | --------------------------- | - | path | string | Yes | Path of the directory in the application sandbox.| - | options | Object | No | File filtering options.| +| Name | Type | Mandatory | Description | +| ------ | ------ | ---- | --------------------------- | +| path | string | Yes | Path of the directory in the application sandbox.| +| options | Object | No | File filtering options.| **options parameters** - | Name | Type | Mandatory | Description | - | ------ | ------ | ---- | --------------------------- | - | recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.| - | listNum | number | No | Number of file names to list. The default value **0** means to list all files.| - | filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.| +| Name | Type | Mandatory | Description | +| ------ | ------ | ---- | --------------------------- | +| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.| +| listNum | number | No | Number of file names to list. The default value **0** means to list all files.| +| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.| **Return value** - | Type | Description | - | --------------------- | ---------- | - | string[] | File names listed.| +| Type | Description | +| --------------------- | ---------- | +| string[] | File names listed.| **Example** @@ -1712,7 +1711,7 @@ Lists all files in a directory synchronously. This API supports recursive listin }; let filenames = fs.listFileSync(pathDir, options); console.info("listFile succeed"); - for (let i = 0; i < filenames.size; i++) { + for (let i = 0; i < filenames.length; i++) { console.info("filename: %s", filenames[i]); } ``` @@ -1726,15 +1725,17 @@ Moves a file. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ------ | ------ | ---- | --------------------------- | - | src | string | Yes | Path of the file to move in the application sandbox.| - | dest | string | Yes | Destination path of the file in the application sandbox.| - | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| +| Name | Type | Mandatory | Description | +| ------ | ------ | ---- | --------------------------- | +| src | string | Yes | Path of the file to move in the application sandbox.| +| dest | string | Yes | Destination path of the file in the application sandbox.| +| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| **Example** ```js + let srcPath = pathDir + '/source.txt'; + let destPath = pathDir + '/dest.txt'; fs.moveFile(srcPath, destPath, 0).then(() => { console.info("move file succeed"); }).catch((err) => { @@ -1752,16 +1753,18 @@ Moves a file. This API uses an asynchronous callback to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ------ | ------ | ---- | --------------------------- | - | src | string | Yes | Path of the file to move in the application sandbox.| - | dest | string | Yes | Destination path of the file in the application sandbox.| - | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| - | callback | AsyncCallback<void> | Yes | Callback invoked when the file is moved. | +| Name | Type | Mandatory | Description | +| ------ | ------ | ---- | --------------------------- | +| src | string | Yes | Path of the file to move in the application sandbox.| +| dest | string | Yes | Destination path of the file in the application sandbox.| +| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| +| callback | AsyncCallback<void> | Yes | Callback invoked when the file is moved. | **Example** ```js + let srcPath = pathDir + '/source.txt'; + let destPath = pathDir + '/dest.txt'; fs.moveFile(srcPath, destPath, 0, (err) => { if (err) { console.info("move file failed with error message: " + err.message + ", error code: " + err.code); @@ -1781,15 +1784,17 @@ Moves a file synchronously. **Parameters** - | Name | Type | Mandatory | Description | - | ------ | ------ | ---- | --------------------------- | - | src | string | Yes | Path of the file to move in the application sandbox.| - | dest | string | Yes | Destination path of the file in the application sandbox.| - | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| +| Name | Type | Mandatory | Description | +| ------ | ------ | ---- | --------------------------- | +| src | string | Yes | Path of the file to move in the application sandbox.| +| dest | string | Yes | Destination path of the file in the application sandbox.| +| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| **Example** ```js + let srcPath = pathDir + '/source.txt'; + let destPath = pathDir + '/dest.txt'; fs.moveFileSync(srcPath, destPath, 0); console.info("move file succeed"); ``` @@ -1804,15 +1809,15 @@ Creates a temporary directory. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ------ | ------ | ---- | --------------------------- | - | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| +| Name | Type | Mandatory | Description | +| ------ | ------ | ---- | --------------------------- | +| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| **Return value** - | Type | Description | - | --------------------- | ---------- | - | Promise<string> | Promise used to return the unique directory generated.| +| Type | Description | +| --------------------- | ---------- | +| Promise<string> | Promise used to return the unique directory generated.| **Example** @@ -1835,10 +1840,10 @@ Creates a temporary directory. This API uses an asynchronous callback to return **Parameters** - | Name | Type | Mandatory | Description | - | -------- | --------------------------- | ---- | --------------------------- | - | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| - | callback | AsyncCallback<string> | Yes | Callback invoked when a temporary directory is created asynchronously. | +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | --------------------------- | +| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| +| callback | AsyncCallback<string> | Yes | Callback invoked when a temporary directory is created asynchronously. | **Example** @@ -1862,21 +1867,21 @@ Synchronously creates a temporary directory. **Parameters** - | Name | Type | Mandatory | Description | - | ------ | ------ | ---- | --------------------------- | - | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| +| Name | Type | Mandatory | Description | +| ------ | ------ | ---- | --------------------------- | +| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| **Return value** - | Type | Description | - | ------ | ---------- | - | string | Unique path generated.| +| Type | Description | +| ------ | ---------- | +| string | Unique path generated.| **Example** ```js let res = fs.mkdtempSync(pathDir + "/XXXXXX"); - ``` + ``` ## fs.createStream @@ -1895,9 +1900,9 @@ Opens a file stream based on the file path. This API uses a promise to return th **Return value** - | Type | Description | - | --------------------------------- | --------- | - | Promise<[Stream](#stream)> | Promise used to return the result.| +| Type | Description | +| --------------------------------- | --------- | +| Promise<[Stream](#stream)> | Promise used to return the result.| **Example** @@ -1957,9 +1962,9 @@ Synchronously opens a stream based on the file path. **Return value** - | Type | Description | - | ------------------ | --------- | - | [Stream](#stream) | Stream opened.| +| Type | Description | +| ------------------ | --------- | +| [Stream](#stream) | Stream opened.| **Example** @@ -1979,16 +1984,16 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| **Return value** - | Type | Description | - | --------------------------------- | --------- | - | Promise<[Stream](#stream)> | Promise used to return the result.| +| Type | Description | +| --------------------------------- | --------- | +| Promise<[Stream](#stream)> | Promise used to return the result.| **Example** @@ -2014,11 +2019,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ---------------------------------------- | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| - | callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. | +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| +| callback | AsyncCallback<[Stream](#stream)> | Yes | Callback invoked when the stream is open asynchronously. | **Example** @@ -2045,16 +2050,16 @@ Synchronously opens a stream based on the file descriptor. **Parameters** - | Name | Type | Mandatory | Description | - | ---- | ------ | ---- | ---------------------------------------- | - | fd | number | Yes | FD of the file. | - | mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| +| Name | Type | Mandatory | Description | +| ---- | ------ | ---- | ---------------------------------------- | +| fd | number | Yes | FD of the file. | +| mode | string | Yes | - **r**: Open a file for reading. The file must exist.
- **r+**: Open a file for both reading and writing. The file must exist.
- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.
- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.
- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).
- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| **Return value** - | Type | Description | - | ------------------ | --------- | - | [Stream](#stream) | Stream opened.| +| Type | Description | +| ------------------ | --------- | +| [Stream](#stream) | Stream opened.| **Example** @@ -2074,7 +2079,7 @@ Represents detailed file information. Before calling any API of the **Stat()** c ### Attributes | Name | Type | Readable | Writable | Description | -| ------ | ------ | ---- | ---- | ---------------------------------------- | +| ------ | ------ | ---- | ---- | ---------------------------------------- | | ino | number | Yes | No | File ID. Different files on the same device have different **ino**s.| | | mode | number | Yes | No | File permissions. The meaning of each bit is as follows:
- **0o400**: The owner has the read permission on a regular file or a directory entry.
- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.
- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.
- **0o040**: The user group has the read permission on a regular file or a directory entry.
- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.
- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.
- **0o004**: Other users have the permission to read a regular file or read a directory entry.
- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.
- **0o001**: Other users have the permission to execute a regular file or search for the specified path in a directory.| | uid | number | Yes | No | ID of the file owner.| @@ -2095,9 +2100,9 @@ Checks whether this file is a block special file. A block special file supports **Return value** - | Type | Description | - | ------- | ---------------- | - | boolean | Whether the file is a block special file.| +| Type | Description | +| ------- | ---------------- | +| boolean | Whether the file is a block special file.| **Example** @@ -2116,9 +2121,9 @@ Checks whether this file is a character special file. A character special file s **Return value** - | Type | Description | - | ------- | ----------------- | - | boolean | Whether the file is a character special file.| +| Type | Description | +| ------- | ----------------- | +| boolean | Whether the file is a character special file.| **Example** @@ -2138,9 +2143,9 @@ Checks whether this file is a directory. **Return value** - | Type | Description | - | ------- | ------------- | - | boolean | Whether the file is a directory.| +| Type | Description | +| ------- | ------------- | +| boolean | Whether the file is a directory.| **Example** @@ -2160,9 +2165,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int **Return value** - | Type | Description | - | ------- | --------------------- | - | boolean | Whether the file is a FIFO.| +| Type | Description | +| ------- | --------------------- | +| boolean | Whether the file is a FIFO.| **Example** @@ -2182,9 +2187,9 @@ Checks whether this file is a regular file. **Return value** - | Type | Description | - | ------- | --------------- | - | boolean | Whether the file is a regular file.| +| Type | Description | +| ------- | --------------- | +| boolean | Whether the file is a regular file.| **Example** @@ -2204,9 +2209,9 @@ Checks whether this file is a socket. **Return value** - | Type | Description | - | ------- | -------------- | - | boolean | Whether the file is a socket.| +| Type | Description | +| ------- | -------------- | +| boolean | Whether the file is a socket.| **Example** @@ -2226,9 +2231,9 @@ Checks whether this file is a symbolic link. **Return value** - | Type | Description | - | ------- | --------------- | - | boolean | Whether the file is a symbolic link.| +| Type | Description | +| ------- | --------------- | +| boolean | Whether the file is a symbolic link.| **Example** @@ -2252,9 +2257,9 @@ Closes the stream. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ------------- | - | Promise<void> | Promise used to return the stream close result.| +| Type | Description | +| ------------------- | ------------- | +| Promise<void> | Promise used to return the stream close result.| **Example** @@ -2279,9 +2284,9 @@ Closes the stream. This API uses an asynchronous callback to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | ------------- | - | callback | AsyncCallback<void> | Yes | Callback invoked when the stream is closed asynchronously.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------- | +| callback | AsyncCallback<void> | Yes | Callback invoked when the stream is closed asynchronously.| **Example** @@ -2323,9 +2328,9 @@ Flushes the stream. This API uses a promise to return the result. **Return value** - | Type | Description | - | ------------------- | ------------- | - | Promise<void> | Promise used to return the stream flushing result.| +| Type | Description | +| ------------------- | ------------- | +| Promise<void> | Promise used to return the stream flushing result.| **Example** @@ -2350,9 +2355,9 @@ Flushes the stream. This API uses an asynchronous callback to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ------------------------- | ---- | -------------- | - | callback | AsyncCallback<void> | Yes | Callback invoked when the stream is asynchronously flushed.| +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | -------------- | +| callback | AsyncCallback<void> | Yes | Callback invoked when the stream is asynchronously flushed.| **Example** @@ -2394,16 +2399,16 @@ Writes data into the stream. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ------------------------------- | ---- | ---------------------------------------- | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to write. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| Name | Type | Mandatory | Description | +| ------- | ------------------------------- | ---- | ---------------------------------------- | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to write. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| **Return value** - | Type | Description | - | --------------------- | -------- | - | Promise<number> | Promise used to return the length of the data written.| +| Type | Description | +| --------------------- | -------- | +| Promise<number> | Promise used to return the length of the data written.| **Example** @@ -2428,11 +2433,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th **Parameters** - | Name | Type | Mandatory| Description | - | -------- | ------------------------------- | ---- | ------------------------------------------------------------ | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| - | callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | +| Name | Type | Mandatory| Description | +| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| callback | AsyncCallback<number> | Yes | Callback invoked when the data is written asynchronously. | **Example** @@ -2460,16 +2465,16 @@ Synchronously writes data into the stream. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ------------------------------- | ---- | ---------------------------------------- | - | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| +| Name | Type | Mandatory | Description | +| ------- | ------------------------------- | ---- | ---------------------------------------- | +| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.
- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.
- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| **Return value** - | Type | Description | - | ------ | -------- | - | number | Length of the data written in the file.| +| Type | Description | +| ------ | -------- | +| number | Length of the data written in the file.| **Example** @@ -2489,16 +2494,16 @@ Reads data from the stream. This API uses a promise to return the result. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. By default, data is read from the current position.| +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. By default, data is read from the current position.| **Return value** - | Type | Description | - | ---------------------------------- | ------ | - | Promise<number> | Promise used to return the data read.| +| Type | Description | +| ---------------------------------- | ------ | +| Promise<number> | Promise used to return the data read.| **Example** @@ -2525,11 +2530,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the **Parameters** - | Name | Type | Mandatory | Description | - | -------- | ---------------------------------------- | ---- | ---------------------------------------- | - | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.| - | callback | AsyncCallback<number> | Yes | Callback invoked when data is read asynchronously from the stream. | +| Name | Type | Mandatory | Description | +| -------- | ---------------------------------------- | ---- | ---------------------------------------- | +| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.| +| callback | AsyncCallback<number> | Yes | Callback invoked when data is read asynchronously from the stream. | **Example** @@ -2557,16 +2562,16 @@ Synchronously reads data from the stream. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | buffer | ArrayBuffer | Yes | Buffer used to store the file read. | - | options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
| +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | +| options | Object | No | The options are as follows:
- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.
- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.
| **Return value** - | Type | Description | - | ------ | -------- | - | number | Length of the data read.| +| Type | Description | +| ------ | -------- | +| number | Length of the data read.| **Example** @@ -2598,15 +2603,15 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | **Return value** - | Type | Description | - | ---------------------------------- | ------ | - | Promise<void> | Promise that returns no value.| +| Type | Description | +| ---------------------------------- | ------ | +| Promise<void> | Promise that returns no value.| **Example** @@ -2629,10 +2634,10 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | - | callback | AsyncCallback<void> | Yes | Callback invoked when the file is locked. | +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | +| callback | AsyncCallback<void> | Yes | Callback invoked when the file is locked. | **Example** @@ -2657,9 +2662,9 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode. **Parameters** - | Name | Type | Mandatory | Description | - | ------- | ----------- | ---- | ---------------------------------------- | - | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | +| Name | Type | Mandatory | Description | +| ------- | ----------- | ---- | ---------------------------------------- | +| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | **Example** diff --git a/en/application-dev/reference/apis/js-apis-file-securityLabel.md b/en/application-dev/reference/apis/js-apis-file-securityLabel.md index 13fd25683a394092653f3f7f93ef36efdaf37bca..c564516e66c0119dbec070c4a9eab744350d130f 100644 --- a/en/application-dev/reference/apis/js-apis-file-securityLabel.md +++ b/en/application-dev/reference/apis/js-apis-file-securityLabel.md @@ -67,7 +67,8 @@ Sets a security label for a file in asynchronous mode. This API uses a promise t **Example** ```js - securityLabel.setSecurityLabel(path, "s0").then(() => { + let filePath = pathDir + '/test.txt'; + securityLabel.setSecurityLabel(filePath, "s0").then(() => { console.info("setSecurityLabel successfully"); }).catch((err) => { console.info("setSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); @@ -93,7 +94,8 @@ Sets a security label for a file in asynchronous mode. This API uses an asynchro **Example** ```js - securityLabel.setSecurityLabel(path, "s0", (err) => { + let filePath = pathDir + '/test.txt'; + securityLabel.setSecurityLabel(filePath, "s0", (err) => { if (err) { console.info("setSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); } else { @@ -120,7 +122,8 @@ Sets a security label for a file in synchronous mode. **Example** ```js -securityLabel.setSecurityLabelSync(path, "s0"); +let filePath = pathDir + '/test.txt'; +securityLabel.setSecurityLabelSync(filePath, "s0"); ``` ## securityLabel.getSecurityLabel @@ -146,7 +149,8 @@ Obtains the security label of a file in asynchronous mode. This API uses a promi **Example** ```js - securityLabel.getSecurityLabel(path).then((type) => { + let filePath = pathDir + '/test.txt'; + securityLabel.getSecurityLabel(filePath).then((type) => { console.log("getSecurityLabel successfully, Label: " + type); }).catch((err) => { console.log("getSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); @@ -171,7 +175,8 @@ Obtains the security label of a file in asynchronous mode. This API uses a callb **Example** ```js - securityLabel.getSecurityLabel(path, (err, type) => { + let filePath = pathDir + '/test.txt'; + securityLabel.getSecurityLabel(filePath, (err, type) => { if (err) { console.log("getSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); } else { @@ -202,6 +207,7 @@ Obtains the security label of a file in synchronous mode. **Example** ```js -let type = securityLabel.getSecurityLabelSync(path); +let filePath = pathDir + '/test.txt'; +let type = securityLabel.getSecurityLabelSync(filePath); console.log("getSecurityLabel successfully, Label: " + type); ``` diff --git a/en/application-dev/reference/apis/js-apis-fileAccess.md b/en/application-dev/reference/apis/js-apis-fileAccess.md index 7cc6188dd1958ba7a158f7b06236206e8055fc9e..da1aebc3030e41ff131cf44b496b01c1fff62d1f 100644 --- a/en/application-dev/reference/apis/js-apis-fileAccess.md +++ b/en/application-dev/reference/apis/js-apis-fileAccess.md @@ -6,6 +6,7 @@ The **fileAccess** module is a framework for accessing and operating user files > >- The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. >- The APIs provided by this module are system APIs and cannot be called by third-party applications. Currently, the APIs can be called only by **FilePicker** and **Files**. +>- The APIs of this module support processing of error codes. For details, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). ## Modules to Import @@ -25,9 +26,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in **Return value** - | Type| Description| - | --- | -- | - | Promise<Array<Want>> | Promise used to return the **want** information obtained.| +| Type| Description| +| --- | -- | +| Promise<Array<Want>> | Promise used to return the **want** information obtained.| **Example** @@ -55,9 +56,9 @@ Obtains information about all wants with **extension** set to **fileAccess** in **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | callback | AsyncCallback<Array<Want>> | Yes| Promise used to return the **want** information obtained.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| callback | AsyncCallback<Array<Want>> | Yes| Promise used to return the **want** information obtained.| **Example** @@ -89,16 +90,16 @@ Synchronously creates a **Helper** object to connect to the specified wants. The **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | context | Context | Yes| Context of the ability.| - | wants | Array<Want> | Yes| Wants to connect.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| context | Context | Yes| Context of the ability.| +| wants | Array<Want> | Yes| Wants to connect.| **Return value** - | Type| Description| - | --- | -- | - | FileAccessHelper | **Helper** object created.| +| Type| Description| +| --- | -- | +| FileAccessHelper | **Helper** object created.| **Example** @@ -136,15 +137,15 @@ Synchronously creates a **Helper** object to connect to all file management serv **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | context | Context | Yes| Context of the ability.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| context | Context | Yes| Context of the ability.| **Return value** - | Type| Description| - | --- | -- | - | FileAccessHelper | **Helper** object created.| +| Type| Description| +| --- | -- | +| FileAccessHelper | **Helper** object created.| **Example** @@ -175,9 +176,9 @@ Obtains information about the device root nodes of the file management service t **Return value** - | Type| Description| - | --- | -- | - | Promise<RootIterator> | Promise used to return the **RootIterator** object obtained.| +| Type| Description| +| --- | -- | +| Promise<RootIterator> | Promise used to return the **RootIterator** object obtained.| **Example** @@ -220,9 +221,9 @@ The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | callback | AsyncCallback<RootIterator> | Yes| Promise used to return the **RootIterator** object obtained.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| callback | AsyncCallback<RootIterator> | Yes| Promise used to return the **RootIterator** object obtained.| **Example** @@ -263,16 +264,16 @@ Synchronously obtains the **FileIterator** object of the first-level files (dire **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | -- | -- | - | filter | Filter | No| **Filter** object. | +| Name| Type| Mandatory| Description| +| --- | --- | -- | -- | +| filter | Filter | No| **Filter** object. | **Return value** - | Type| Description| - | --- | -- | - | FileIterator | **FileIterator** object obtained.| +| Type| Description| +| --- | -- | +| FileIterator | **FileIterator** object obtained.| **Example** @@ -314,15 +315,15 @@ Recursively obtains the **FileIterator** object of the files matching the condit **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | -- | -- | - | filter | Filter | No| **Filter** object. | +| Name| Type| Mandatory| Description| +| --- | --- | -- | -- | +| filter | Filter | No| **Filter** object. | **Return value** - | Type| Description| - | --- | -- | - | FileIterator | **FileIterator** object obtained.| +| Type| Description| +| --- | -- | +| FileIterator | **FileIterator** object obtained.| **Example** @@ -364,15 +365,15 @@ Synchronously obtains the **FileIterator** object of the next-level files (direc **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | -- | -- | - | filter | Filter | No| **Filter** object. | +| Name| Type| Mandatory| Description| +| --- | --- | -- | -- | +| filter | Filter | No| **Filter** object. | **Return value** - | Type| Description| - | --- | -- | - | FileIterator | **FileIterator** object obtained.| +| Type| Description| +| --- | -- | +| FileIterator | **FileIterator** object obtained.| **Example** @@ -414,16 +415,16 @@ Recursively obtains the **FileIterator** object of the files matching the condit **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | -- | -- | - | filter | Filter | No| **Filter** object. | +| Name| Type| Mandatory| Description| +| --- | --- | -- | -- | +| filter | Filter | No| **Filter** object. | **Return value** - | Type| Description| - | --- | -- | - | FileIterator | **FileIterator** object obtained.| +| Type| Description| +| --- | -- | +| FileIterator | **FileIterator** object obtained.| **Example** @@ -465,10 +466,10 @@ Creates a file in a directory. This API uses a promise to return the result. **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | uri | string | Yes| URI of the parent directory for the file to create.| - | displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| uri | string | Yes| URI of the parent directory for the file to create.| +| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.| **Return value** @@ -510,11 +511,11 @@ Creates a file in a directory. This API uses an asynchronous callback to return **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | uri | string | Yes| URI of the parent directory for the file to create.| - | displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.| - | callback | AsyncCallback<string> | Yes| Promise used to return the URI of the file created.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| uri | string | Yes| URI of the parent directory for the file to create.| +| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.| +| callback | AsyncCallback<string> | Yes| Promise used to return the URI of the file created.| **Example** @@ -550,10 +551,10 @@ Creates a directory. This API uses a promise to return the result. **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | parentUri | string | Yes| URI of the parent directory for the directory to create.| - | displayName | string | Yes| Name of the directory to create.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| parentUri | string | Yes| URI of the parent directory for the directory to create.| +| displayName | string | Yes| Name of the directory to create.| **Return value** @@ -595,11 +596,11 @@ Creates a directory. This API uses an asynchronous callback to return the result **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | parentUri | string | Yes| URI of the parent directory for the directory to create.| - | displayName | string | Yes| Name of the directory to create.| - | callback | AsyncCallback<string> | Yes| Promise used to return the URI of the directory created.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| parentUri | string | Yes| URI of the parent directory for the directory to create.| +| displayName | string | Yes| Name of the directory to create.| +| callback | AsyncCallback<string> | Yes| Promise used to return the URI of the directory created.| **Example** @@ -635,10 +636,10 @@ Opens a file. This API uses a promise to return the result. **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | uri | string | Yes| URI of the file to open.| - | flags | [OPENFLAGS](#openflags) | Yes| File open mode.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| uri | string | Yes| URI of the file to open.| +| flags | [OPENFLAGS](#openflags) | Yes| File open mode.| **Return value** @@ -673,11 +674,11 @@ Opens a file. This API uses an asynchronous callback to return the result. **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | uri | string | Yes| URI of the file to open.| - | flags | [OPENFLAGS](#openflags) | Yes| File open mode.| - | callback | AsyncCallback<number> | Yes| Callback invoked to return the file descriptor of the file opened.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| uri | string | Yes| URI of the file to open.| +| flags | [OPENFLAGS](#openflags) | Yes| File open mode.| +| callback | AsyncCallback<number> | Yes| Callback invoked to return the file descriptor of the file opened.| **Example** @@ -712,9 +713,9 @@ Deletes a file or directory. This API uses a promise to return the result. **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | uri | string | Yes| URI of the file or directory to delete.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| uri | string | Yes| URI of the file or directory to delete.| **Return value** @@ -751,10 +752,10 @@ Deletes a file or directory. This API uses an asynchronous callback to return th **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | uri | string | Yes| URI of the file or directory to delete.| - | callback | AsyncCallback<number> | Yes| Promise used to return the result.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| uri | string | Yes| URI of the file or directory to delete.| +| callback | AsyncCallback<number> | Yes| Promise used to return the result.| **Example** @@ -781,7 +782,7 @@ Deletes a file or directory. This API uses an asynchronous callback to return th move(sourceFile: string, destFile: string) : Promise<string> -Moves a file or directory. This API uses a promise to return the result. +Moves a file or directory. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.UserFileService @@ -789,22 +790,22 @@ Moves a file or directory. This API uses a promise to return the result. **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | sourceFile | string | Yes| URI of the file or directory to move.| - | destFile | string | Yes| URI of the directory, to which the file or directory will be moved.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| sourceFile | string | Yes| URI of the file or directory to move.| +| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.| **Return value** | Type| Description| | ----- | ------ | -| Promise<string> | Promise used to return the URI of the file or directory in the destination directory.| +| Promise<string> | Promise used to return the URI of the file or directory in the destination directory.| **Example** ```js // The media library URI is used as an example. - //In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo. + //In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo. // You can use the URI obtained. let sourceFile = "datashare:///media/file/102"; let destFile = "datashare:///media/file/101"; @@ -821,7 +822,7 @@ Moves a file or directory. This API uses a promise to return the result. move(sourceFile: string, destFile: string, callback: AsyncCallback<string>) : void; -Moves a file or directory. This API uses an asynchronous callback to return the result. +Moves a file or directory. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.FileManagement.UserFileService @@ -829,17 +830,17 @@ Moves a file or directory. This API uses an asynchronous callback to return the **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | sourceFile | string | Yes| URI of the file or directory to move.| - | destFile | string | Yes| URI of the directory, to which the file or directory will be moved.| - | callback | AsyncCallback<string> | Yes| Promise used to return the URI of the file or directory in the destination directory.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| sourceFile | string | Yes| URI of the file or directory to move.| +| destFile | string | Yes| URI of the directory, to which the file or directory will be moved.| +| callback | AsyncCallback<string> | Yes| Promise used to return the URI of the file or directory in the destination directory.| **Example** ```js // The media library URI is used as an example. - //In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo. + //In the sample code, sourceFile destFile indicates the file or directory in the Download directory. The URI is the URI in fileInfo. // You can use the URI obtained. let sourceFile = "datashare:///media/file/102"; let destFile = "datashare:///media/file/101"; @@ -861,7 +862,7 @@ Moves a file or directory. This API uses an asynchronous callback to return the rename(uri: string, displayName: string) : Promise<string> -Renames a file or directory. This API uses a promise to return the result. +Renames a file or directory. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.UserFileService @@ -869,16 +870,16 @@ Renames a file or directory. This API uses a promise to return the result. **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | uri | string | Yes| URI of the file or directory to rename.| - | displayName | string | Yes| New name of the file or directory, which can contain the file name extension.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| uri | string | Yes| URI of the file or directory to rename.| +| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.| **Return value** | Type| Description| | --- | -- | -| Promise<string> | Promise used to return the URI of the renamed file or directory.| +| Promise<string> | Promise used to return the URI of the renamed file or directory.| **Example** @@ -900,7 +901,7 @@ Renames a file or directory. This API uses a promise to return the result. rename(uri: string, displayName: string, callback: AsyncCallback<string>) : void; -Renames a file or directory. This API uses an asynchronous callback to return the result. +Renames a file or directory. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.FileManagement.UserFileService @@ -908,11 +909,11 @@ Renames a file or directory. This API uses an asynchronous callback to return t **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | uri | string | Yes| URI of the file or directory to rename.| - | displayName | string | Yes| New name of the file or directory, which can contain the file name extension.| - | callback | AsyncCallback<string> | Yes| Promise used to return the URI of the renamed file or directory.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| uri | string | Yes| URI of the file or directory to rename.| +| displayName | string | Yes| New name of the file or directory, which can contain the file name extension.| +| callback | AsyncCallback<string> | Yes| Promise used to return the URI of the renamed file or directory.| **Example** @@ -939,7 +940,7 @@ Renames a file or directory. This API uses an asynchronous callback to return t access(sourceFileUri: string) : Promise<boolean> -Checks whether a file or directory exists. This API uses a promise to return the result. +Checks whether a file or directory exists. This API uses a promise to return the result. **System capability**: SystemCapability.FileManagement.UserFileService @@ -947,9 +948,9 @@ Checks whether a file or directory exists. This API uses a promise to return th **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | sourceFileUri | string | Yes| URI of the file or directory.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| sourceFileUri | string | Yes| URI of the file or directory.| **Return value** @@ -980,7 +981,7 @@ Checks whether a file or directory exists. This API uses a promise to return th access(sourceFileUri: string, callback: AsyncCallback<boolean>) : void; -Checks whether a file or directory exists. This API uses an asynchronous callback to return the result. +Checks whether a file or directory exists. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.FileManagement.UserFileService @@ -988,10 +989,10 @@ Checks whether a file or directory exists. This API uses an asynchronous callba **Parameters** - | Name| Type| Mandatory| Description| - | --- | --- | --- | -- | - | sourceFileUri | string | Yes| URI of the file or directory.| - | callback | AsyncCallback<boolean> | Yes| Promise used to return the result.| +| Name| Type| Mandatory| Description| +| --- | --- | --- | -- | +| sourceFileUri | string | Yes| URI of the file or directory.| +| callback | AsyncCallback<boolean> | Yes| Promise used to return the result.| **Example** @@ -1031,13 +1032,13 @@ Obtains the next-level device root directory. **RootIterator** is an iterator ob | Type| Description| | --- | -- | -| {value: RootInfo, done: boolean} | Root directory information obtained. This API traverses the directory until **done** returns **true**. The **value** field contains the root directory information.| +| {value: RootInfo, done: boolean} | Root directory information obtained. This API traverses the directory until **done** returns **true**. The **value** field contains the root directory information.| ## FileIterator.next next( ) : { value: FileInfo, done: boolean } -Obtains the information about the next-level file or directory. **FileIterator** is an iterator object of a directory. +Obtains the information about the next-level file or directory. **FileIterator** is an iterator object of a directory. **System capability**: SystemCapability.FileManagement.UserFileService @@ -1047,7 +1048,7 @@ Obtains the information about the next-level file or directory. **FileIterator* | Type| Description| | --- | -- | -| {value: FileInfo, done: boolean} | File or directory information obtained. This API traverses the specified directory until **done** returns **true**. The **value** field contains the file or directory information obtained.| +| {value: FileInfo, done: boolean} | File or directory information obtained. This API traverses the specified directory until **done** returns **true**. The **value** field contains the file or directory information obtained.| ## RootInfo @@ -1068,7 +1069,7 @@ Represents the root attribute information and interface capabilities of a device ## FileInfo -Represents the file or directory attribute information and interface capabilities. +Represents the file or directory attribute information and interface capabilities. **System capability**: SystemCapability.FileManagement.UserFileService @@ -1078,12 +1079,12 @@ Represents the file or directory attribute information and interface capabiliti | Name| Type | Readable| Writable| Description | | ------ | ------ | -------- | ------ | -------- | -| uri | string | Yes| No| URI of the file or directory.| -| fileName | string | Yes| No| Name of a file or directory.| -| mode | number | Yes| No| Permissions on the file or directory.| -| size | number | Yes| No| Size of the file or directory.| -| mtime | number | Yes| No| Time when the file or directory was last modified.| -| mimeType | string | Yes| No| MIME type of the file or directory.| +| uri | string | Yes| No| URI of the file or directory.| +| fileName | string | Yes| No| Name of a file or directory.| +| mode | number | Yes| No| Permissions on the file or directory.| +| size | number | Yes| No| Size of the file or directory.| +| mtime | number | Yes| No| Time when the file or directory was last modified.| +| mimeType | string | Yes| No| MIME type of the file or directory.| ## OPENFLAGS diff --git a/en/application-dev/reference/apis/js-apis-nfcController.md b/en/application-dev/reference/apis/js-apis-nfcController.md index 105af3cf95ca3a052faddbb6fe632940169fbcd1..9381cdcdbae18cedf6ca6814c3df141e509062d1 100644 --- a/en/application-dev/reference/apis/js-apis-nfcController.md +++ b/en/application-dev/reference/apis/js-apis-nfcController.md @@ -1,14 +1,14 @@ -# Standard NFC +# @ohos.nfc.controller (Standard NFC) The **nfcController** module provides APIs for opening and closing Near-Field Communication (NFC) and reading the NFC state. -> **NOTE**
+> **NOTE** +> > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. - ## **Modules to Import** -``` +```js import controller from '@ohos.nfc.controller'; ``` @@ -18,7 +18,7 @@ Enumerates the NFC states. **System capability**: SystemCapability.Communication.NFC.Core -| Name| Default Value| Description| +| Name| Value| Description| | -------- | -------- | -------- | | STATE_OFF | 1 | NFC is closed (OFF).| | STATE_TURNING_ON | 2 | NFC is turning on.| @@ -31,6 +31,9 @@ isNfcAvailable(): boolean Checks whether the device supports NFC. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use canIUse("SystemCapability.Communication.NFC.Core"). + **System capability**: SystemCapability.Communication.NFC.Core **Return value** @@ -46,6 +49,9 @@ openNfc(): boolean Opens NFC. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [enableNfc](#controllerenablenfc9). + **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **System capability**: SystemCapability.Communication.NFC.Core @@ -56,12 +62,33 @@ Opens NFC. | -------- | -------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| +## controller.enableNfc9+ + +enableNfc(): boolean + +Opens NFC. + +**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS + +**System capability**: SystemCapability.Communication.NFC.Core + +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error Message| +| ------- | -------| +| 3100101 | NFC state is abnormal in service. | + ## controller.closeNfc closeNfc(): boolean Closes NFC. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [disableNfc](#controllerdisablenfc9). + **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **System capability**: SystemCapability.Communication.NFC.Core @@ -72,6 +99,24 @@ Closes NFC. | -------- | ------------------------------------------- | | boolean | Returns **true** if the operation is successful; returns **false** otherwise.| +## controller.disableNfc9+ + +disableNfc(): boolean + +Closes NFC. + +**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS + +**System capability**: SystemCapability.Communication.NFC.Core + +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error Message| +| ------- | -------| +| 3100101 | NFC state is abnormal in service. | + ## controller.isNfcOpen isNfcOpen(): boolean @@ -108,14 +153,12 @@ Subscribes to NFC state changes. A callback will be invoked to return the NFC st **System capability**: SystemCapability.Communication.NFC.Core -**Parameter** +**Parameters** - | **Name**| **Type**| **Mandatory**| **Description**| - | -------- | -------- | -------- | -------- | - | type | string | Yes| Event type to subscribe to. The value is **nfcStateChange**.| - | callback | Callback<[NfcState](#nfcstate)> | Yes| Callback invoked to return the NFC state.| - - +| **Name**| **Type**| **Mandatory**| **Description**| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Event type to subscribe to. The value is **nfcStateChange**.| +| callback | Callback<[NfcState](#nfcstate)> | Yes| Callback invoked to return the NFC state.| ## controller.off('nfcStateChange') @@ -125,42 +168,55 @@ Unsubscribes from the NFC state changes. The subscriber will not receive NFC sta **System capability**: SystemCapability.Communication.NFC.Core -**Parameter** - - | **Name**| **Type**| **Mandatory**| **Description**| - | -------- | -------- | -------- | -------- | - | type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.| +**Parameters** + +| **Name**| **Type**| **Mandatory**| **Description**| +| -------- | -------- | -------- | -------- | +| type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.| | callback | Callback<[NfcState](#nfcstate)> | No| Callback for the NFC state changes. This parameter can be left blank.| **Example** - ```js - import controller from '@ohos.nfc.controller'; - - // Define a callback key. - var NFC_STATE_CALLBACK_KEY = "nfcStateChange"; - - // Register the callback to receive NFC state change notifications. - controller.on(NFC_STATE_CALLBACK_KEY, (err, nfcState)=> { - if (err) { - console.log("controller on callback err: " + err); - } else { - console.log("controller on callback nfcState: " + nfcState); - } - }); - - // Open NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS. - if (!controller.isNfcOpen()) { - var ret = controller.openNfc(); - console.log("controller openNfc ret: " + ret); - } +```js +import controller from '@ohos.nfc.controller'; - // Close NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS. - if (controller.isNfcOpen()) { - var ret = controller.closeNfc(); - console.log("controller closeNfc ret: " + ret); +// Register the callback to receive NFC state change notifications. +controller.on("nfcStateChange", (err, nfcState)=> { + if (err) { + console.log("controller on callback err: " + err); + } else { + console.log("controller on callback nfcState: " + nfcState); } +}); - // Unregister the callback. - controller.off(NFC_STATE_CALLBACK_KEY); - ``` + // Open NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS. +if (!controller.isNfcOpen()) { + var ret = controller.openNfc(); + console.log("controller openNfc ret: " + ret); +} + +// Use 'enableNfc' to enable NFC from API version 9. +try { + controller.enableNfc(); + console.log("controller enableNfc success"); +} catch (busiError) { + console.log("controller enableNfc busiError: " + busiError); +} + +// Close NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS. +if (controller.isNfcOpen()) { + var ret = controller.closeNfc(); + console.log("controller closeNfc ret: " + ret); +} + +// Use 'disableNfc' to disable NFC from API version 9. +try { + controller.disableNfc(); + console.log("controller disableNfc success"); +} catch (busiError) { + console.log("controller disableNfc busiError: " + busiError); +} + +// Unregister the callback. +controller.off("nfcStateChange"); +``` diff --git a/en/application-dev/reference/apis/js-apis-nfcTag.md b/en/application-dev/reference/apis/js-apis-nfcTag.md index ead2c9bc9653f591b4521588f6f3215782cd4e7a..2dbf451d5202e7d7f7139cfb930007763732eade 100644 --- a/en/application-dev/reference/apis/js-apis-nfcTag.md +++ b/en/application-dev/reference/apis/js-apis-nfcTag.md @@ -73,7 +73,7 @@ onCreate(want, launchParam) { try { tagInfo = tag.getTagInfo(want); } catch (error) { - console.log("tag.getTagInfo catched error: " + error); + console.log("tag.getTagInfo caught error: " + error); } if (tagInfo == null || tagInfo == undefined) { console.log("no TagInfo to be created, ignore it."); @@ -100,7 +100,7 @@ onCreate(want, launchParam) { try { nfcA = tag.getNfcATag(taginfo); } catch (error) { - console.log("tag.getNfcATag catched error: " + error); + console.log("tag.getNfcATag caught error: " + error); } // Other code to read or write this tag. } @@ -111,7 +111,7 @@ onCreate(want, launchParam) { try { isoDep = tag.getIsoDep(taginfo); } catch (error) { - console.log("tag.getIsoDep catched error: " + error); + console.log("tag.getIsoDep caught error: " + error); } // Other code to read or write this tag. } @@ -126,64 +126,204 @@ getNfcATag(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag) Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology. -**Required permissions**: ohos.permission.NFC_TAG +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcA](#taggetnfca9). + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------------------------- | ---- | ---------------------------------------- | +| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. + +**Return value** + +| **Type**| **Description**| +| -------- | -------- | +| [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.| + +## tag.getNfcA9+ + +getNfcA(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag) + +Obtains an **NfcATag** object, which allows access to the tags that use the NFC-A technology. **System capability**: SystemCapability.Communication.NFC.Tag +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------------------------- | ---- | ---------------------------------------- | +| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. + **Return value** | **Type**| **Description**| | -------- | -------- | | [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.| +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error Message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + ## tag.getNfcBTag getNfcBTag(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag) Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology. -**Required permissions**: ohos.permission.NFC_TAG +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcB](#taggetnfcb9). + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------------------------- | ---- | ---------------------------------------- | +| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. + +**Return value** + +| **Type**| **Description** | +| -------- | ---------------- | +| [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.| + +## tag.getNfcB9+ + +getNfcB(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag) + +Obtains an **NfcBTag** object, which allows access to the tags that use the NFC-B technology. **System capability**: SystemCapability.Communication.NFC.Tag +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------------------------- | ---- | ---------------------------------------- | +| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. + **Return value** | **Type**| **Description** | | -------- | ---------------- | | [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.| +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error Message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + ## tag.getNfcFTag getNfcFTag(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag) Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology. -**Required permissions**: ohos.permission.NFC_TAG +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcF](#taggetnfcf9). + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------------------------- | ---- | ---------------------------------------- | +| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. + +**Return value** + +| **Type**| **Description** | +| -------- | ---------------- | +| [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.| + +## tag.getNfcF9+ + +getNfcF(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag) + +Obtains an **NfcFTag** object, which allows access to the tags that use the NFC-F technology. **System capability**: SystemCapability.Communication.NFC.Tag +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------------------------- | ---- | ---------------------------------------- | +| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. + **Return value** | **Type**| **Description** | | -------- | ---------------- | | [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.| +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error Message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + ## tag.getNfcVTag getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag) Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology. -**Required permissions**: ohos.permission.NFC_TAG +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getNfcV](#taggetnfcv9). + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------------------------- | ---- | ---------------------------------------- | +| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. + +**Return value** + +| **Type**| **Description** | +| -------- | ---------------- | +| [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.| + +## tag.getNfcV9+ + +getNfcV(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag) + +Obtains an **NfcVTag** object, which allows access to the tags that use the NFC-V technology. **System capability**: SystemCapability.Communication.NFC.Tag +**Parameters** + +| Name | Type | Mandatory | Description | +| --------- | ------------------------- | ---- | ---------------------------------------- | +| taginfo | [TagInfo](#taginfo) | Yes| Tag information including the technology type and related parameters, which are obtained from **tag.getTagInfo(want: Want)**. + **Return value** | **Type**| **Description** | | -------- | ---------------- | | [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.| +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error Message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + ## tag.getIsoDep9+ getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 ) diff --git a/en/application-dev/reference/apis/js-apis-nfctech.md b/en/application-dev/reference/apis/js-apis-nfctech.md index c3a4a8858d84aae84f905d5beb9b21a557324344..49d4d31f3bfe67c400d473e0068297fc0bfff4d6 100644 --- a/en/application-dev/reference/apis/js-apis-nfctech.md +++ b/en/application-dev/reference/apis/js-apis-nfctech.md @@ -26,8 +26,6 @@ getSak(): number Obtains the SAK value of this NFC-A tag. -**Required permissions**: ohos.permission.NFC_TAG - **System capability**: SystemCapability.Communication.NFC.Tag **Return value** @@ -52,8 +50,6 @@ getAtqa(): number[] Obtains the ATQA value of this NFC-A tag. -**Required permissions**: ohos.permission.NFC_TAG - **System capability**: SystemCapability.Communication.NFC.Tag **Return value** @@ -86,8 +82,6 @@ getRespAppData(): number[] Obtains the application data of this NFC-B tag. -**Required permissions**: ohos.permission.NFC_TAG - **System capability**: SystemCapability.Communication.NFC.Tag **Return value** @@ -112,8 +106,6 @@ getRespProtocol(): number[] Obtains the protocol information of this NFC-B tag. -**Required permissions**: ohos.permission.NFC_TAG - **System capability**: SystemCapability.Communication.NFC.Tag **Return value** @@ -146,8 +138,6 @@ getSystemCode(): number[] Obtains the system code from this NFC-F tag. -**Required permissions**: ohos.permission.NFC_TAG - **System capability**: SystemCapability.Communication.NFC.Tag **Return value** @@ -172,8 +162,6 @@ getPmm(): number[] Obtains the PMm (consisting of the IC code and manufacturer parameters) information from this NFC-F tag. -**Required permissions**: ohos.permission.NFC_TAG - **System capability**: SystemCapability.Communication.NFC.Tag **Return value** @@ -206,8 +194,6 @@ getResponseFlags(): number Obtains the response flags from this NFC-V tag. -**Required permissions**: ohos.permission.NFC_TAG - **System capability**: SystemCapability.Communication.NFC.Tag **Return value** @@ -232,8 +218,6 @@ getDsfId(): number Obtains the data storage format identifier (DSFID) from this NFC-V tag. -**Required permissions**: ohos.permission.NFC_TAG - **System capability**: SystemCapability.Communication.NFC.Tag **Return value** diff --git a/en/application-dev/reference/apis/js-apis-rpc.md b/en/application-dev/reference/apis/js-apis-rpc.md index 22d23791ce29915d8ca90980d81a4b33ba4a1e35..cb7ee5a7e4ef6dfa073ec47f94ce5b0244d0d032 100644 --- a/en/application-dev/reference/apis/js-apis-rpc.md +++ b/en/application-dev/reference/apis/js-apis-rpc.md @@ -5653,7 +5653,7 @@ Obtains a proxy or remote object. This API must be implemented by its derived cl return this; } } - let remoteObject = new TestAbility().asObject(); + let remoteObject = new TestAbility("testObject").asObject(); ``` **Example** @@ -8263,13 +8263,13 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode } } let testRemoteObject = new TestRemoteObject("testObject"); + console.log("RpcServer: descriptor is: " + descriptor); try { let descriptor = testRemoteObject.getDescriptor(); } catch(error) { console.info("rpc get local interface fail, errorCode " + error.code); console.info("rpc get local interface fail, errorMessage " + error.message); } - console.log("RpcServer: descriptor is: " + descriptor); ``` ### getInterfaceDescriptor(deprecated) @@ -8344,8 +8344,8 @@ Binds an interface descriptor to an **IRemoteBroker** object. try { this.modifyLocalInterface(this, descriptor); } catch(error) { - console.info(rpc attach local interface fail, errorCode " + error.code); - console.info(rpc attach local interface fail, errorMessage " + error.message); + console.info(" rpc attach local interface fail, errorCode " + error.code); + console.info(" rpc attach local interface fail, errorMessage " + error.message); } } registerDeathRecipient(recipient: MyDeathRecipient, flags: number) { diff --git a/en/application-dev/reference/apis/js-apis-tagSession.md b/en/application-dev/reference/apis/js-apis-tagSession.md index 183c9089d1771394b49dea1d2f16bf85c9066910..0104bbc993f6532606c7fd5a0470d14c70a08552 100644 --- a/en/application-dev/reference/apis/js-apis-tagSession.md +++ b/en/application-dev/reference/apis/js-apis-tagSession.md @@ -26,6 +26,9 @@ getTagInfo(): tag.TagInfo Obtains the **tagInfo** object provided by the NFC service when the tag is dispatched. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tag.getTagInfo](js-apis-nfcTag.md#taggettaginfo9). + **Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag @@ -54,6 +57,9 @@ connectTag(): boolean; Connects to this tag. Call this API to set up a connection before reading data from or writing data to a tag. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.connect](#tagsessionconnect9). + **Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag @@ -76,12 +82,49 @@ let connectStatus = tag.getIsoDep(tagInfo).connectTag(); console.log("connectStatus: " + connectStatus); ``` +### tagSession.connect9+ + +connect(): void; + +Connects to this tag. Call this API to set up a connection before reading data from or writing data to a tag. + +**Required permissions**: ohos.permission.NFC_TAG + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + +**Example** + +```js +import tag from '@ohos.nfc.tag'; + +// tagInfo is an object provided by the NFC service when a tag is dispatched. +// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags. + +try { + tag.getIsoDep(tagInfo).connect(); + console.log("tag connect success"); +} catch (busiError) { + console.log("tag connect busiError: " + busiError); +} +``` + ### tagSession.reset() reset(): void Resets the connection to this tag. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.resetConnection](#tagsessionresetconnection9). + **Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag @@ -97,12 +140,49 @@ import tag from '@ohos.nfc.tag'; tag.getIsoDep(tagInfo).reset(); ``` +### tagSession.resetConnection()9+ + +resetConnection(): void + +Resets the connection to this tag. + +**Required permissions**: ohos.permission.NFC_TAG + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + +**Example** + +```js +import tag from '@ohos.nfc.tag'; + +// tagInfo is an object provided by the NFC service when a tag is dispatched. +// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags. + +try { + tag.getIsoDep(tagInfo).resetConnection(); + console.log("tag resetConnection success"); +} catch (busiError) { + console.log("tag resetConnection busiError: " + busiError); +} +``` + ### tagSession.isTagConnected isTagConnected(): boolean Checks whether the tag is connected. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.isConnected](#tagsessionisconnected9). + **Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag @@ -125,12 +205,47 @@ let isTagConnected = tag.getIsoDep(tagInfo).isTagConnected(); console.log("isTagConnected: " + isTagConnected); ``` +### tagSession.isConnected9+ + +isConnected(): boolean + +Checks whether the tag is connected. + +**Required permissions**: ohos.permission.NFC_TAG + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Return value** + +| **Type**| **Description** | +| ------------------ | --------------------------| +| boolean | Returns **true** if the tag is connected; returns **false** otherwise.| + +**Example** + +```js +import tag from '@ohos.nfc.tag'; + +// tagInfo is an object provided by the NFC service when a tag is dispatched. +// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags. + +try { + var isConnected = tag.getIsoDep(tagInfo).isConnected(); + console.log("tag isConnected = " + isConnected); +} catch (busiError) { + console.log("tag isConnected busiError: " + busiError); +} +``` + ### tagSession.getMaxSendLength getMaxSendLength(): number Obtains the maximum length of the data that can be sent to this tag. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.getMaxTransmitSize](#tagsessiongetmaxtransmitsize9). + **Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag @@ -152,12 +267,54 @@ let maxSendLen = tag.getIsoDep(tagInfo).getMaxSendLength(); console.log("tag maxSendLen: " + maxSendLen); ``` +### tagSession.getMaxTransmitSize9+ + +getMaxTransmitSize(): number + +Obtains the maximum length of the data that can be sent to this tag. + +**Required permissions**: ohos.permission.NFC_TAG + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Return value** + +| **Type**| **Description** | +| ------------------ | --------------------------| +| number | Maximum data length obtained. The value cannot be a negative number.| + +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + +**Example** +```js +import tag from '@ohos.nfc.tag'; + +// tagInfo is an object provided by the NFC service when a tag is dispatched. +// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags. + +try { + var maxTransmitSize = tag.getIsoDep(tagInfo).getMaxTransmitSize(); + console.log("tag maxTransmitSize = " + maxTransmitSize); +} catch (busiError) { + console.log("tag getMaxTransmitSize busiError: " + busiError); +} +``` + ### tagSession.getSendDataTimeout getSendDataTimeout(): number Obtains the timeout period for sending data to this tag, in milliseconds. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.getTimeout](#tagsessiongettimeout9). + **Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag @@ -180,12 +337,55 @@ let sendDataTimeout = tag.getIsoDep(tagInfo).getSendDataTimeout(); console.log("tag sendDataTimeout: " + sendDataTimeout); ``` +### tagSession.getTimeout9+ + +getTimeout(): number + +Obtains the timeout period for sending data to this tag, in milliseconds. + +**Required permissions**: ohos.permission.NFC_TAG + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Return value** + +| **Type**| **Description** | +| ------------------ | --------------------------| +| number | Timeout period obtained, in milliseconds. The value cannot be a negative number.| + +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + +**Example** + +```js +import tag from '@ohos.nfc.tag'; + +// tagInfo is an object provided by the NFC service when a tag is dispatched. +// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags. + +try { + var timeout = tag.getIsoDep(tagInfo).getTimeout(); + console.log("tag timeout = " + timeout); +} catch (busiError) { + console.log("tag getTimeout busiError: " + busiError); +} +``` + ### tagSession.setSendDataTimeout setSendDataTimeout(timeout: number): boolean Sets the timeout period for sending data to this tag, in milliseconds. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.setTimeout](#tagsessionsettimeout9). + **Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag @@ -215,12 +415,56 @@ let setStatus = tag.getIsoDep(tagInfo).setSendDataTimeout(timeoutMs); console.log("tag setSendDataTimeout setStatus: " + setStatus); ``` +### tagSession.setTimeout9+ + +setTimeout(timeout: number): void + +Obtains the timeout period for sending data to this tag, in milliseconds. + +**Required permissions**: ohos.permission.NFC_TAG + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | -------------------------------------- | +| timeout | number | Yes| Timeout period to set, in milliseconds. The value cannot be a negative number.| + +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + +**Example** + +```js +import tag from '@ohos.nfc.tag'; + +// tagInfo is an object provided by the NFC service when a tag is dispatched. +// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags. + +let timeoutMs = 700; // Change it as required. +try { + tag.getIsoDep(tagInfo).setTimeout(timeoutMs); + console.log("tag setTimeout success"); +} catch (busiError) { + console.log("tag setTimeout busiError: " + busiError); +} +``` + ### tagSession.sendData sendData(data: number[]): Promise Sends data to this tag. This API uses a promise to return the result. +> **NOTE** +> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [tagSession.transmit](#tagsessiontransmit9). + **Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag @@ -267,6 +511,9 @@ sendData(data: number[], callback: AsyncCallback): void Sends data to this tag. This API uses an asynchronous callback to return the result. +> **NOTE** +> This parameter is supported since API version 7 and discarded since API version 9. You are advised to use [tagSession.transmit](#tagsessiontransmit9-1). + **Required permissions**: ohos.permission.NFC_TAG **System capability**: SystemCapability.Communication.NFC.Tag @@ -303,3 +550,123 @@ tag.getIsoDep(tagInfo).sendData(cmdData, (err, response)=> { } }); ``` + +### tagSession.transmit9+ + +transmit(data: number[]): Promise + +Sends data to this tag. This API uses a promise to return the result. + +**Required permissions**: ohos.permission.NFC_TAG + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | -------------------------------------- | +| data | number[] | Yes| Data to send. The data consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| + +**Return value** + +| **Type**| **Description** | +| ------------------ | --------------------------| +| Promise | Promise used to return the response from the tag. The response consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| + +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + +**Example** + +```js +import tag from '@ohos.nfc.tag'; + +// tagInfo is an object provided by the NFC service when a tag is dispatched. +// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags. + +// Connect to the tag if it is not connected. +try { + if (!tag.getIsoDep(tagInfo).isConnected()) { + tag.getIsoDep(tagInfo).connect(); + } +} catch (busiError) { + console.log("tag connect busiError: " + busiError); + return; +} + +let cmdData = [0x01, 0x02, 0x03, 0x04]; // Change it as required. +try { + tag.getIsoDep(tagInfo).transmit(cmdData).then((response) => { + console.log("tagSession transmit Promise response: " + response); + }).catch((err)=> { + console.log("tagSession transmit Promise err: " + err); + }); +} catch (busiError) { + console.log("tag transmit busiError: " + busiError); + return; +} +``` + +### tagSession.transmit9+ + +transmit(data: number[], callback: AsyncCallback): void + +Sends data to this tag. This API uses an asynchronous callback to return the result. + +**Required permissions**: ohos.permission.NFC_TAG + +**System capability**: SystemCapability.Communication.NFC.Tag + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ----------------------- | ---- | -------------------------------------- | +| data | number[] | Yes| Data to send. The data consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| +| callback | AsyncCallback | Yes| Callback invoked to return the response from the tag. The response consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| + +**Error codes** + +For details about the error codes, see [NFC Error Codes](../errorcodes/errorcode-nfc.md). + +| ID| Error message| +| ------- | -------| +| 3100201 | Tag running state is abnormal in service. | + +**Example** + +```js +import tag from '@ohos.nfc.tag'; + +// tagInfo is an object provided by the NFC service when a tag is dispatched. +// getXXX can be getIsoDep, getNdef, getMifareClassic, or any other getter for NFC tags. + +// Connect to the tag if it is not connected. +try { + if (!tag.getIsoDep(tagInfo).isConnected()) { + tag.getIsoDep(tagInfo).connect(); + } +} catch (busiError) { + console.log("tag connect busiError: " + busiError); + return; +} + +let cmdData = [0x01, 0x02, 0x03, 0x04]; // Change it as required. +try { + tag.getIsoDep(tagInfo).transmit(cmdData, (err, response)=> { + if (err) { + console.log("tagSession transmit AsyncCallback err: " + err); + } else { + console.log("tagSession transmit AsyncCallback response: " + response); + } + }); +} catch (busiError) { + console.log("tag transmit busiError: " + busiError); + return; +} + +``` diff --git a/en/application-dev/reference/apis/js-apis-useriam-userauth.md b/en/application-dev/reference/apis/js-apis-useriam-userauth.md index f555df967ddc3a5f11d498bae739be54d1ad53ad..ce3611111a266910c302c779ee5eadc0b1fdc06c 100644 --- a/en/application-dev/reference/apis/js-apis-useriam-userauth.md +++ b/en/application-dev/reference/apis/js-apis-useriam-userauth.md @@ -22,8 +22,8 @@ Defines the authentication result. | ------------ | ---------- | ---- | -------------------- | | result | number | Yes | Authentication result. | | token | Uint8Array | No | Token that has passed the user identity authentication.| -| remainAttempts | number | No | Number of remaining authentication times allowed.| -| lockoutDuration | number | No | Time for which the authentication operation is frozen.| +| remainAttempts | number | No | Number of remaining authentication attempts.| +| lockoutDuration | number | No | Lock duration of the authentication operation, in milliseconds.| ## TipInfo9+ diff --git a/en/application-dev/reference/errorcodes/errorcode-nfc.md b/en/application-dev/reference/errorcodes/errorcode-nfc.md index 500d870366c8a88a9036454ada2d0ffe0a3c04a9..4169a40d6388d0883088621e0dba243f0c6d050f 100644 --- a/en/application-dev/reference/errorcodes/errorcode-nfc.md +++ b/en/application-dev/reference/errorcodes/errorcode-nfc.md @@ -4,7 +4,7 @@ **Error Message** -NFC opening or closing state is abnormal in service. +NFC state is abnormal in service. **Description** @@ -12,11 +12,13 @@ The NFC service fails to enable or disable NFC. **Possible Causes** -Communication with the NFC service failed. +1. Communication with the NFC service failed. +2. The NFC chip communication is abnormal. **Solution** -Enable or disable NFC again. +1. Enable or disable NFC again. +2. Enable or disable NFC again or restart the device, and try again. ## 3100201 @@ -30,7 +32,7 @@ An error occurs when the NFC service executes the tag service logic. **Possible Causes** 1. The tag parameters do not match the API to invoke. -2. The NFC is disabled. +2. NFC is disabled. 3. The tag is disconnected before the tag operation. 4. The tag chip returns an error status or response timeout. 5. Binding with the NFC service has not been established. diff --git a/en/release-notes/changelogs/OpenHarmony_3.2.10.3/changelogs-nfc.md b/en/release-notes/changelogs/OpenHarmony_3.2.10.3/changelogs-nfc.md new file mode 100644 index 0000000000000000000000000000000000000000..b4cccb7e0e18556fcda82b4733daf7f16ffbc846 --- /dev/null +++ b/en/release-notes/changelogs/OpenHarmony_3.2.10.3/changelogs-nfc.md @@ -0,0 +1,61 @@ +# Changelog of NFC JS APIs in the Communication Subsystem + +Compared with OpenHarmony 3.2 Beta4, OpenHarmony 3.2.10.2(Mr) has the following changes in NFC APIs: + +## cl.nfc.1 API Change +Deprecated some NFC JS APIs in API versions 6 to 8 because the APIs cannot throw error codes, and added new APIs in API version 9 instead. + +You need to adapt your application. + + **Change Impact** + +The deprecated JS APIs in API versions 6 to 8 are affected. Your application needs to adapt new APIs so that it can properly implement functions in the SDK environment of the new version. + +**Key API/Component Changes** + +| Module | Class | Method/Attribute/Enum/Constant | Change Type| +| ------------------------- | ------------------- | ------------------------------------------------------------ | -------- | +| api/@ohos.nfc.cardEmulation.d.ts | cardEmulation | FeatureType | Deprecated | +| api/@ohos.nfc.cardEmulation.d.ts | cardEmulation | isSupported | Deprecated | +| api/@ohos.nfc.cardEmulation.d.ts | cardEmulation | hasHceCapability | Added | +| api/@ohos.nfc.controller.d.ts | nfcController | isNfcAvailable | Deprecated | +| api/@ohos.nfc.controller.d.ts | nfcController | openNfc | Deprecated | +| api/@ohos.nfc.controller.d.ts | nfcController | closeNfc | Deprecated | +| api/@ohos.nfc.controller.d.ts | nfcController | enableNfc | Added | +| api/@ohos.nfc.controller.d.ts | nfcController | disableNfc | Added | +| api/@ohos.nfc.tag.d.ts | tag | getNfcATag | Deprecated | +| api/@ohos.nfc.tag.d.ts | tag | getNfcBTag | Deprecated | +| api/@ohos.nfc.tag.d.ts | tag | getNfcFTag | Deprecated | +| api/@ohos.nfc.tag.d.ts | tag | getNfcVTag | Deprecated | +| api/@ohos.nfc.tag.d.ts | tag | getNfcA | Added | +| api/@ohos.nfc.tag.d.ts | tag | getNfcB | Added | +| api/@ohos.nfc.tag.d.ts | tag | getNfcF | Added | +| api/@ohos.nfc.tag.d.ts | tag | getNfcV | Added | +| api/tag/tagSession.d.ts | TagSession | getTagInfo | Deprecated | +| api/tag/tagSession.d.ts | TagSession | connectTag | Deprecated | +| api/tag/tagSession.d.ts | TagSession | reset | Deprecated | +| api/tag/tagSession.d.ts | TagSession | isTagConnected | Deprecated | +| api/tag/tagSession.d.ts | TagSession | setSendDataTimeout | Deprecated | +| api/tag/tagSession.d.ts | TagSession | getSendDataTimeout | Deprecated | +| api/tag/tagSession.d.ts | TagSession | sendData | Deprecated | +| api/tag/tagSession.d.ts | TagSession | getMaxSendLength | Deprecated | +| api/tag/tagSession.d.ts | TagSession | connect | Added | +| api/tag/tagSession.d.ts | TagSession | resetConnection | Added | +| api/tag/tagSession.d.ts | TagSession | isConnected | Added | +| api/tag/tagSession.d.ts | TagSession | setTimeout | Added | +| api/tag/tagSession.d.ts | TagSession | getTimeout | Added | +| api/tag/tagSession.d.ts | TagSession | transmit | Added | +| api/tag/tagSession.d.ts | TagSession | getMaxTransmitSize | Added | + +**Adaptation Guide** + +See the following: +[@ohos.nfc.cardEmulation (Standard NFC Card Emulation)](../../../application-dev/reference/apis/js-apis-cardEmulation.md) + +[@ohos.nfc.controller (Standard NFC)](../../../application-dev/reference/apis/js-apis-nfcController.md) + +[@ohos.nfc.tag (Standard NFC Tags)](../../../application-dev/reference/apis/js-apis-nfcTag.md) + +[tagSession (Standard NFC Tag Session)](../../../application-dev/reference/apis/js-apis-tagSession.md) + +