“ca988bdc98bf560a833e1033ccced92afb5e5aff”上不存在“paddle/git@gitcode.net:s920243400/PaddleDetection.git”
提交 a3f5f717 编写于 作者: A Annie_wang

Update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 5cc343cf
...@@ -16,31 +16,37 @@ import cardEmulation from '@ohos.nfc.cardEmulation'; ...@@ -16,31 +16,37 @@ import cardEmulation from '@ohos.nfc.cardEmulation';
Enumerates the NFC card emulation types. 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 **System capability**: SystemCapability.Communication.NFC.CardEmulation
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| HCE | 0 | HCE.| | HCE | 0 | HCE.|
| UICC | 1 | Subscriber identity module (SIM) card emulation.| | UICC | 1 | Subscriber identity module (SIM) card emulation.|
| ESE | 2 | embedded Secure Element (eSE) emulation.| | ESE | 2 | embedded Secure Element (eSE) emulation.|
## CardType ## CardType<sup>9+</sup>
Enumerates the card emulation application types. Enumerates the types of services used by the card emulation application.
**System capability**: SystemCapability.Communication.NFC.CardEmulation **System capability**: SystemCapability.Communication.NFC.CardEmulation
| Name| Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| PAYMENT | "payment" | Payment type.| | PAYMENT | "payment" | Payment type.|
| OTHER | "other" | Other types. | | OTHER | "other" | Other types.|
## cardEmulation.isSupported ## isSupported
isSupported(feature: number): boolean isSupported(feature: number): boolean
Checks whether a certain type of card emulation is supported. 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 **System capability**: SystemCapability.Communication.NFC.CardEmulation
**Parameters** **Parameters**
...@@ -55,89 +61,44 @@ Checks whether a certain type of card emulation is supported. ...@@ -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.| | boolean | Returns **true** if the card emulation type is supported; returns **false** otherwise.|
## cardEmulation.isDefaultService ## hasHceCapability<sup>9+</sup>
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 **System capability**: SystemCapability.Communication.NFC.CardEmulation
**Parameters** **Required permissions**: ohos.permission.NFC_CARD_EMULATION
| 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.|
**Return value** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.| | boolean | Returns **true** if HCE is supported; returns **false** otherwise.|
## HceService<sup>8+</sup>
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. ## isDefaultService<sup>9+</sup>
### startHCE<sup>8+</sup> 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 **Required permissions**: ohos.permission.NFC_CARD_EMULATION
**System capability**: SystemCapability.Communication.NFC.CardEmulation
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | -------- | ---- | ----------------------- | | ------- | -------- | ---- | ----------------------- |
| aidList | string[] | Yes | AID list to register.| | 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.|
### stopHCE<sup>8+</sup>
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
### on<sup>8+</sup>
on(type: "hceCmd", callback: AsyncCallback<number[]>): void;
Registers a callback to receive APDUs from the peer card reader. **Return value**
**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<number[]> | Yes | Callback invoked to return the APDU, which consists of hexadecimal numbers ranging from **0x00** to **0xFF**.|
### sendResponse<sup>8+</sup>
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**
| Name | Type | Mandatory| Description | | **Type**| **Description**|
| ------------ | -------- | ---- | -------------------------------------------------- | | -------- | -------- |
| responseApdu | number[] | Yes | Response APDU sent to the peer card reader. The value consists of hexadecimal numbers ranging from **0x00** to **0xFF**.| | boolean | Returns **true** if the application is the default payment application; returns **false** otherwise.|
**Example** **Example**
...@@ -150,30 +111,16 @@ if (!isHceSupported) { ...@@ -150,30 +111,16 @@ if (!isHceSupported) {
return; return;
} }
var hasHceCap = cardEmulation.hasHceCapability();
if (!hasHceCap) {
console.log('this device hasHceCapability false, ignore it.');
return;
}
var elementName = { var elementName = {
"bundleName": "com.test.cardemulation", "bundleName": "com.test.cardemulation",
"abilityName": "com.test.cardemulation.MainAbility", "abilityName": "com.test.cardemulation.MainAbility",
}; };
var isDefaultService = cardEmulation.isDefaultService(elementName, cardEmulation.CardType.PAYMENT); var isDefaultService = cardEmulation.isDefaultService(elementName, cardEmulation.CardType.PAYMENT);
console.log('is the app is default service for this card type: ' + isDefaultService); 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();
``` ```
...@@ -51,7 +51,7 @@ For details about the supported specifications, see [HMAC Algorithm Specificatio ...@@ -51,7 +51,7 @@ For details about the supported specifications, see [HMAC Algorithm Specificatio
| Name | Type | Mandatory| Description | | 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** **Return value**
...@@ -483,7 +483,7 @@ For details about the supported specifications, see [MD Algorithm Specifications ...@@ -483,7 +483,7 @@ For details about the supported specifications, see [MD Algorithm Specifications
| Name | Type | Mandatory| Description | | 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** **Return value**
...@@ -1852,7 +1852,7 @@ Updates the data to encrypt or decrypt by segment. This API uses a promise to re ...@@ -1852,7 +1852,7 @@ Updates the data to encrypt or decrypt by segment. This API uses a promise to re
| Type | Description | | 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** **Error codes**
...@@ -2267,6 +2267,8 @@ Signs the data. This API uses a promise to return the result. ...@@ -2267,6 +2267,8 @@ Signs the data. This API uses a promise to return the result.
| -------------- | ----------- | | -------------- | ----------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result.|
**Error codes**
| ID| Error Message | | ID| Error Message |
| -------- | ---------------------- | | -------- | ---------------------- |
| 17620001 | memory error. | | 17620001 | memory error. |
......
...@@ -8,7 +8,7 @@ The **relationalStore** module provides the following functions: ...@@ -8,7 +8,7 @@ The **relationalStore** module provides the following functions:
- [RdbStore](#rdbstore): provides APIs for managing data in an RDB store. - [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. - [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store.
> **NOTE**<br/> > **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 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 ...@@ -30,7 +30,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>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. | | config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes | Callback invoked to return the RDB store obtained. | | callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | 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 ...@@ -108,7 +108,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | -------------------------------- | ---- | ------------------------------------------------------------ | | ------- | -------------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>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. | | config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
**Return value** **Return value**
...@@ -188,7 +188,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul ...@@ -188,7 +188,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>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. | | name | string | Yes | Name of the RDB store to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
...@@ -249,7 +249,7 @@ Deletes an RDB store. This API uses a promise 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 | | Name | Type | Mandatory| Description |
| ------- | ------- | ---- | ------------------------------------------------------------ | | ------- | ------- | ---- | ------------------------------------------------------------ |
| context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>For details about the application context of the stage model, see [Context](js-apis-ability-context.md).| | context | Context | Yes | Application context.<br>For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).<br>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. | | name | string | Yes | Name of the RDB store to delete. |
**Return value** **Return value**
...@@ -363,6 +363,8 @@ Defines the database synchronization mode. ...@@ -363,6 +363,8 @@ Defines the database synchronization mode.
Defines the subscription type. Defines the subscription type.
**Required permissions**: ohos.permission.DISTRIBUTED_DATASYNC
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core **System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
| Name | Value | Description | | Name | Value | Description |
...@@ -2430,9 +2432,9 @@ Synchronizes data between devices. This API uses a promise to return the result. ...@@ -2430,9 +2432,9 @@ Synchronizes data between devices. This API uses a promise to return the result.
let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.inDevices(['12345678abcde']); predicates.inDevices(['12345678abcde']);
let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates); let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates);
promise.then((resultSet) =>{ promise.then((result) =>{
console.info(`Sync done.`); 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]}`); console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
} }
}).catch((err) => { }).catch((err) => {
...@@ -2511,10 +2513,12 @@ Provides APIs to access the result set obtained by querying the RDB store. A res ...@@ -2511,10 +2513,12 @@ Provides APIs to access the result set obtained by querying the RDB store. A res
Obtain the **resultSet** object first. Obtain the **resultSet** object first.
```js ```js
let resultSet = null;
let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("AGE", 18); predicates.equalTo("AGE", 18);
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); 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 columnNames: ${resultSet.columnNames}`);
console.info(`resultSet columnCount: ${resultSet.columnCount}`); console.info(`resultSet columnCount: ${resultSet.columnCount}`);
}); });
...@@ -2685,7 +2689,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode ...@@ -2685,7 +2689,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
resultSet.(5); resultSet.goToRow(5);
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.error(`query failed, err: ${err}`); console.error(`query failed, err: ${err}`);
......
...@@ -67,7 +67,8 @@ Sets a security label for a file in asynchronous mode. This API uses a promise t ...@@ -67,7 +67,8 @@ Sets a security label for a file in asynchronous mode. This API uses a promise t
**Example** **Example**
```js ```js
securityLabel.setSecurityLabel(path, "s0").then(() => { let filePath = pathDir + '/test.txt';
securityLabel.setSecurityLabel(filePath, "s0").then(() => {
console.info("setSecurityLabel successfully"); console.info("setSecurityLabel successfully");
}).catch((err) => { }).catch((err) => {
console.info("setSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); 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 ...@@ -93,7 +94,8 @@ Sets a security label for a file in asynchronous mode. This API uses an asynchro
**Example** **Example**
```js ```js
securityLabel.setSecurityLabel(path, "s0", (err) => { let filePath = pathDir + '/test.txt';
securityLabel.setSecurityLabel(filePath, "s0", (err) => {
if (err) { if (err) {
console.info("setSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); console.info("setSecurityLabel failed with error message: " + err.message + ", error code: " + err.code);
} else { } else {
...@@ -120,7 +122,8 @@ Sets a security label for a file in synchronous mode. ...@@ -120,7 +122,8 @@ Sets a security label for a file in synchronous mode.
**Example** **Example**
```js ```js
securityLabel.setSecurityLabelSync(path, "s0"); let filePath = pathDir + '/test.txt';
securityLabel.setSecurityLabelSync(filePath, "s0");
``` ```
## securityLabel.getSecurityLabel ## securityLabel.getSecurityLabel
...@@ -146,7 +149,8 @@ Obtains the security label of a file in asynchronous mode. This API uses a promi ...@@ -146,7 +149,8 @@ Obtains the security label of a file in asynchronous mode. This API uses a promi
**Example** **Example**
```js ```js
securityLabel.getSecurityLabel(path).then((type) => { let filePath = pathDir + '/test.txt';
securityLabel.getSecurityLabel(filePath).then((type) => {
console.log("getSecurityLabel successfully, Label: " + type); console.log("getSecurityLabel successfully, Label: " + type);
}).catch((err) => { }).catch((err) => {
console.log("getSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); 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 ...@@ -171,7 +175,8 @@ Obtains the security label of a file in asynchronous mode. This API uses a callb
**Example** **Example**
```js ```js
securityLabel.getSecurityLabel(path, (err, type) => { let filePath = pathDir + '/test.txt';
securityLabel.getSecurityLabel(filePath, (err, type) => {
if (err) { if (err) {
console.log("getSecurityLabel failed with error message: " + err.message + ", error code: " + err.code); console.log("getSecurityLabel failed with error message: " + err.message + ", error code: " + err.code);
} else { } else {
...@@ -202,6 +207,7 @@ Obtains the security label of a file in synchronous mode. ...@@ -202,6 +207,7 @@ Obtains the security label of a file in synchronous mode.
**Example** **Example**
```js ```js
let type = securityLabel.getSecurityLabelSync(path); let filePath = pathDir + '/test.txt';
let type = securityLabel.getSecurityLabelSync(filePath);
console.log("getSecurityLabel successfully, Label: " + type); console.log("getSecurityLabel successfully, Label: " + type);
``` ```
# 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. The **nfcController** module provides APIs for opening and closing Near-Field Communication (NFC) and reading the NFC state.
> **NOTE**<br> > **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. > 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** ## **Modules to Import**
``` ```js
import controller from '@ohos.nfc.controller'; import controller from '@ohos.nfc.controller';
``` ```
...@@ -18,7 +18,7 @@ Enumerates the NFC states. ...@@ -18,7 +18,7 @@ Enumerates the NFC states.
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
| Name| Default Value| Description| | Name| Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| STATE_OFF | 1 | NFC is closed (OFF).| | STATE_OFF | 1 | NFC is closed (OFF).|
| STATE_TURNING_ON | 2 | NFC is turning on.| | STATE_TURNING_ON | 2 | NFC is turning on.|
...@@ -31,6 +31,9 @@ isNfcAvailable(): boolean ...@@ -31,6 +31,9 @@ isNfcAvailable(): boolean
Checks whether the device supports NFC. 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 **System capability**: SystemCapability.Communication.NFC.Core
**Return value** **Return value**
...@@ -46,6 +49,9 @@ openNfc(): boolean ...@@ -46,6 +49,9 @@ openNfc(): boolean
Opens NFC. 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 **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
...@@ -56,12 +62,33 @@ Opens NFC. ...@@ -56,12 +62,33 @@ Opens NFC.
| -------- | -------- | | -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## controller.enableNfc<sup>9+</sup>
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 ## controller.closeNfc
closeNfc(): boolean closeNfc(): boolean
Closes NFC. 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 **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
...@@ -72,6 +99,24 @@ Closes NFC. ...@@ -72,6 +99,24 @@ Closes NFC.
| -------- | ------------------------------------------- | | -------- | ------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.| | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
## controller.disableNfc<sup>9+</sup>
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 ## controller.isNfcOpen
isNfcOpen(): boolean isNfcOpen(): boolean
...@@ -108,14 +153,12 @@ Subscribes to NFC state changes. A callback will be invoked to return the NFC st ...@@ -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 **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to subscribe to. The value is **nfcStateChange**.| | type | string | Yes| Event type to subscribe to. The value is **nfcStateChange**.|
| callback | Callback&lt;[NfcState](#nfcstate)&gt; | Yes| Callback invoked to return the NFC state.| | callback | Callback&lt;[NfcState](#nfcstate)&gt; | Yes| Callback invoked to return the NFC state.|
## controller.off('nfcStateChange') ## controller.off('nfcStateChange')
...@@ -125,42 +168,55 @@ Unsubscribes from the NFC state changes. The subscriber will not receive NFC sta ...@@ -125,42 +168,55 @@ Unsubscribes from the NFC state changes. The subscriber will not receive NFC sta
**System capability**: SystemCapability.Communication.NFC.Core **System capability**: SystemCapability.Communication.NFC.Core
**Parameter** **Parameters**
| **Name**| **Type**| **Mandatory**| **Description**| | **Name**| **Type**| **Mandatory**| **Description**|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.| | type | string | Yes| Event type to unsubscribe from. The value is **nfcStateChange**.|
| callback | Callback&lt;[NfcState](#nfcstate)&gt; | No| Callback for the NFC state changes. This parameter can be left blank.| | callback | Callback&lt;[NfcState](#nfcstate)&gt; | No| Callback for the NFC state changes. This parameter can be left blank.|
**Example** **Example**
```js ```js
import controller from '@ohos.nfc.controller'; 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);
}
// Close NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS. // Register the callback to receive NFC state change notifications.
if (controller.isNfcOpen()) { controller.on("nfcStateChange", (err, nfcState)=> {
var ret = controller.closeNfc(); if (err) {
console.log("controller closeNfc ret: " + ret); console.log("controller on callback err: " + err);
} else {
console.log("controller on callback nfcState: " + nfcState);
} }
});
// Unregister the callback. // Open NFC. Require permission: ohos.permission.MANAGE_SECURE_SETTINGS.
controller.off(NFC_STATE_CALLBACK_KEY); 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");
```
...@@ -73,7 +73,7 @@ onCreate(want, launchParam) { ...@@ -73,7 +73,7 @@ onCreate(want, launchParam) {
try { try {
tagInfo = tag.getTagInfo(want); tagInfo = tag.getTagInfo(want);
} catch (error) { } catch (error) {
console.log("tag.getTagInfo catched error: " + error); console.log("tag.getTagInfo caught error: " + error);
} }
if (tagInfo == null || tagInfo == undefined) { if (tagInfo == null || tagInfo == undefined) {
console.log("no TagInfo to be created, ignore it."); console.log("no TagInfo to be created, ignore it.");
...@@ -100,7 +100,7 @@ onCreate(want, launchParam) { ...@@ -100,7 +100,7 @@ onCreate(want, launchParam) {
try { try {
nfcA = tag.getNfcATag(taginfo); nfcA = tag.getNfcATag(taginfo);
} catch (error) { } catch (error) {
console.log("tag.getNfcATag catched error: " + error); console.log("tag.getNfcATag caught error: " + error);
} }
// Other code to read or write this tag. // Other code to read or write this tag.
} }
...@@ -111,7 +111,7 @@ onCreate(want, launchParam) { ...@@ -111,7 +111,7 @@ onCreate(want, launchParam) {
try { try {
isoDep = tag.getIsoDep(taginfo); isoDep = tag.getIsoDep(taginfo);
} catch (error) { } catch (error) {
console.log("tag.getIsoDep catched error: " + error); console.log("tag.getIsoDep caught error: " + error);
} }
// Other code to read or write this tag. // Other code to read or write this tag.
} }
...@@ -126,64 +126,204 @@ getNfcATag(tagInfo: [TagInfo](#taginfo)): [NfcATag](js-apis-nfctech.md#nfcatag) ...@@ -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. 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.getNfcA<sup>9+</sup>
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 **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** **Return value**
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| [NfcATag](js-apis-nfctech.md#nfcatag) | **NfcATag** object obtained.| | [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 ## tag.getNfcBTag
getNfcBTag(tagInfo: [TagInfo](#taginfo)): [NfcBTag](js-apis-nfctech.md#nfcbtag) 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. 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.getNfcB<sup>9+</sup>
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 **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** **Return value**
| **Type**| **Description** | | **Type**| **Description** |
| -------- | ---------------- | | -------- | ---------------- |
| [NfcBTag](js-apis-nfctech.md#nfcbtag) | **NfcBTag** object obtained.| | [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 ## tag.getNfcFTag
getNfcFTag(tagInfo: [TagInfo](#taginfo)): [NfcFTag](js-apis-nfctech.md#nfcftag) 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. 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.getNfcF<sup>9+</sup>
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 **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** **Return value**
| **Type**| **Description** | | **Type**| **Description** |
| -------- | ---------------- | | -------- | ---------------- |
| [NfcFTag](js-apis-nfctech.md#nfcftag) | **NfcFTag** object obtained.| | [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 ## tag.getNfcVTag
getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag) 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. 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.getNfcV<sup>9+</sup>
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 **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** **Return value**
| **Type**| **Description** | | **Type**| **Description** |
| -------- | ---------------- | | -------- | ---------------- |
| [NfcVTag](js-apis-nfctech.md#nfcvtag) | **NfcVTag** object obtained.| | [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.getIsoDep<sup>9+</sup> ## tag.getIsoDep<sup>9+</sup>
getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 ) getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 )
......
...@@ -26,8 +26,6 @@ getSak(): number ...@@ -26,8 +26,6 @@ getSak(): number
Obtains the SAK value of this NFC-A tag. Obtains the SAK value of this NFC-A tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -52,8 +50,6 @@ getAtqa(): number[] ...@@ -52,8 +50,6 @@ getAtqa(): number[]
Obtains the ATQA value of this NFC-A tag. Obtains the ATQA value of this NFC-A tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -86,8 +82,6 @@ getRespAppData(): number[] ...@@ -86,8 +82,6 @@ getRespAppData(): number[]
Obtains the application data of this NFC-B tag. Obtains the application data of this NFC-B tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -112,8 +106,6 @@ getRespProtocol(): number[] ...@@ -112,8 +106,6 @@ getRespProtocol(): number[]
Obtains the protocol information of this NFC-B tag. Obtains the protocol information of this NFC-B tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -146,8 +138,6 @@ getSystemCode(): number[] ...@@ -146,8 +138,6 @@ getSystemCode(): number[]
Obtains the system code from this NFC-F tag. Obtains the system code from this NFC-F tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -172,8 +162,6 @@ getPmm(): number[] ...@@ -172,8 +162,6 @@ getPmm(): number[]
Obtains the PMm (consisting of the IC code and manufacturer parameters) information from this NFC-F tag. 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 **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -206,8 +194,6 @@ getResponseFlags(): number ...@@ -206,8 +194,6 @@ getResponseFlags(): number
Obtains the response flags from this NFC-V tag. Obtains the response flags from this NFC-V tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
...@@ -232,8 +218,6 @@ getDsfId(): number ...@@ -232,8 +218,6 @@ getDsfId(): number
Obtains the data storage format identifier (DSFID) from this NFC-V tag. Obtains the data storage format identifier (DSFID) from this NFC-V tag.
**Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
**Return value** **Return value**
......
...@@ -5653,7 +5653,7 @@ Obtains a proxy or remote object. This API must be implemented by its derived cl ...@@ -5653,7 +5653,7 @@ Obtains a proxy or remote object. This API must be implemented by its derived cl
return this; return this;
} }
} }
let remoteObject = new TestAbility().asObject(); let remoteObject = new TestAbility("testObject").asObject();
``` ```
**Example** **Example**
...@@ -8263,13 +8263,13 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode ...@@ -8263,13 +8263,13 @@ For details about the error codes, see [RPC Error Codes](../errorcodes/errorcode
} }
} }
let testRemoteObject = new TestRemoteObject("testObject"); let testRemoteObject = new TestRemoteObject("testObject");
console.log("RpcServer: descriptor is: " + descriptor);
try { try {
let descriptor = testRemoteObject.getDescriptor(); let descriptor = testRemoteObject.getDescriptor();
} catch(error) { } catch(error) {
console.info("rpc get local interface fail, errorCode " + error.code); console.info("rpc get local interface fail, errorCode " + error.code);
console.info("rpc get local interface fail, errorMessage " + error.message); console.info("rpc get local interface fail, errorMessage " + error.message);
} }
console.log("RpcServer: descriptor is: " + descriptor);
``` ```
### getInterfaceDescriptor<sup>(deprecated)</sup> ### getInterfaceDescriptor<sup>(deprecated)</sup>
...@@ -8344,8 +8344,8 @@ Binds an interface descriptor to an **IRemoteBroker** object. ...@@ -8344,8 +8344,8 @@ Binds an interface descriptor to an **IRemoteBroker** object.
try { try {
this.modifyLocalInterface(this, descriptor); this.modifyLocalInterface(this, descriptor);
} catch(error) { } catch(error) {
console.info(rpc attach local interface fail, errorCode " + error.code); 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, errorMessage " + error.message);
} }
} }
registerDeathRecipient(recipient: MyDeathRecipient, flags: number) { registerDeathRecipient(recipient: MyDeathRecipient, flags: number) {
......
...@@ -26,6 +26,9 @@ getTagInfo(): tag.TagInfo ...@@ -26,6 +26,9 @@ getTagInfo(): tag.TagInfo
Obtains the **tagInfo** object provided by the NFC service when the tag is dispatched. 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 **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
...@@ -54,6 +57,9 @@ connectTag(): boolean; ...@@ -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. 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 **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
...@@ -76,12 +82,49 @@ let connectStatus = tag.getIsoDep(tagInfo).connectTag(); ...@@ -76,12 +82,49 @@ let connectStatus = tag.getIsoDep(tagInfo).connectTag();
console.log("connectStatus: " + connectStatus); console.log("connectStatus: " + connectStatus);
``` ```
### tagSession.connect<sup>9+</sup>
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() ### tagSession.reset()
reset(): void reset(): void
Resets the connection to this tag. 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 **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
...@@ -97,12 +140,49 @@ import tag from '@ohos.nfc.tag'; ...@@ -97,12 +140,49 @@ import tag from '@ohos.nfc.tag';
tag.getIsoDep(tagInfo).reset(); tag.getIsoDep(tagInfo).reset();
``` ```
### tagSession.resetConnection()<sup>9+</sup>
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 ### tagSession.isTagConnected
isTagConnected(): boolean isTagConnected(): boolean
Checks whether the tag is connected. 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 **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
...@@ -125,12 +205,47 @@ let isTagConnected = tag.getIsoDep(tagInfo).isTagConnected(); ...@@ -125,12 +205,47 @@ let isTagConnected = tag.getIsoDep(tagInfo).isTagConnected();
console.log("isTagConnected: " + isTagConnected); console.log("isTagConnected: " + isTagConnected);
``` ```
### tagSession.isConnected<sup>9+</sup>
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 ### tagSession.getMaxSendLength
getMaxSendLength(): number getMaxSendLength(): number
Obtains the maximum length of the data that can be sent to this tag. 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 **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
...@@ -152,12 +267,54 @@ let maxSendLen = tag.getIsoDep(tagInfo).getMaxSendLength(); ...@@ -152,12 +267,54 @@ let maxSendLen = tag.getIsoDep(tagInfo).getMaxSendLength();
console.log("tag maxSendLen: " + maxSendLen); console.log("tag maxSendLen: " + maxSendLen);
``` ```
### tagSession.getMaxTransmitSize<sup>9+</sup>
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 ### tagSession.getSendDataTimeout
getSendDataTimeout(): number getSendDataTimeout(): number
Obtains the timeout period for sending data to this tag, in milliseconds. 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 **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
...@@ -180,12 +337,55 @@ let sendDataTimeout = tag.getIsoDep(tagInfo).getSendDataTimeout(); ...@@ -180,12 +337,55 @@ let sendDataTimeout = tag.getIsoDep(tagInfo).getSendDataTimeout();
console.log("tag sendDataTimeout: " + sendDataTimeout); console.log("tag sendDataTimeout: " + sendDataTimeout);
``` ```
### tagSession.getTimeout<sup>9+</sup>
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 ### tagSession.setSendDataTimeout
setSendDataTimeout(timeout: number): boolean setSendDataTimeout(timeout: number): boolean
Sets the timeout period for sending data to this tag, in milliseconds. 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 **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
...@@ -215,12 +415,56 @@ let setStatus = tag.getIsoDep(tagInfo).setSendDataTimeout(timeoutMs); ...@@ -215,12 +415,56 @@ let setStatus = tag.getIsoDep(tagInfo).setSendDataTimeout(timeoutMs);
console.log("tag setSendDataTimeout setStatus: " + setStatus); console.log("tag setSendDataTimeout setStatus: " + setStatus);
``` ```
### tagSession.setTimeout<sup>9+</sup>
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 ### tagSession.sendData
sendData(data: number[]): Promise<number[]> sendData(data: number[]): Promise<number[]>
Sends data to this tag. This API uses a promise to return the result. 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 **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
...@@ -267,6 +511,9 @@ sendData(data: number[], callback: AsyncCallback<number[]>): void ...@@ -267,6 +511,9 @@ sendData(data: number[], callback: AsyncCallback<number[]>): void
Sends data to this tag. This API uses an asynchronous callback to return the result. 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 **Required permissions**: ohos.permission.NFC_TAG
**System capability**: SystemCapability.Communication.NFC.Tag **System capability**: SystemCapability.Communication.NFC.Tag
...@@ -303,3 +550,123 @@ tag.getIsoDep(tagInfo).sendData(cmdData, (err, response)=> { ...@@ -303,3 +550,123 @@ tag.getIsoDep(tagInfo).sendData(cmdData, (err, response)=> {
} }
}); });
``` ```
### tagSession.transmit<sup>9+</sup>
transmit(data: number[]): Promise<number[]>
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<number[]> | 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.transmit<sup>9+</sup>
transmit(data: number[], callback: AsyncCallback<number[]>): 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<number[]> | 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;
}
```
...@@ -22,8 +22,8 @@ Defines the authentication result. ...@@ -22,8 +22,8 @@ Defines the authentication result.
| ------------ | ---------- | ---- | -------------------- | | ------------ | ---------- | ---- | -------------------- |
| result | number | Yes | Authentication result. | | result | number | Yes | Authentication result. |
| token | Uint8Array | No | Token that has passed the user identity authentication.| | token | Uint8Array | No | Token that has passed the user identity authentication.|
| remainAttempts | number | No | Number of remaining authentication times allowed.| | remainAttempts | number | No | Number of remaining authentication attempts.|
| lockoutDuration | number | No | Time for which the authentication operation is frozen.| | lockoutDuration | number | No | Lock duration of the authentication operation, in milliseconds.|
## TipInfo<sup>9+</sup> ## TipInfo<sup>9+</sup>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
**Error Message** **Error Message**
NFC opening or closing state is abnormal in service. NFC state is abnormal in service.
**Description** **Description**
...@@ -12,11 +12,13 @@ The NFC service fails to enable or disable NFC. ...@@ -12,11 +12,13 @@ The NFC service fails to enable or disable NFC.
**Possible Causes** **Possible Causes**
Communication with the NFC service failed. 1. Communication with the NFC service failed.
2. The NFC chip communication is abnormal.
**Solution** **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 ## 3100201
...@@ -30,7 +32,7 @@ An error occurs when the NFC service executes the tag service logic. ...@@ -30,7 +32,7 @@ An error occurs when the NFC service executes the tag service logic.
**Possible Causes** **Possible Causes**
1. The tag parameters do not match the API to invoke. 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. 3. The tag is disconnected before the tag operation.
4. The tag chip returns an error status or response timeout. 4. The tag chip returns an error status or response timeout.
5. Binding with the NFC service has not been established. 5. Binding with the NFC service has not been established.
......
# 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)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册