• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import type { AsyncCallback, BusinessError, Callback } from './@ohos.base';
17
18/**
19 * Provides methods to operate or manage Connected Tag.
20 *
21 * @namespace connectedTag
22 * @syscap SystemCapability.Communication.ConnectedTag
23 * @since 8
24 */
25declare namespace connectedTag {
26  /**
27   * Initializes Connected Tag.
28   *
29   * @permission ohos.permission.NFC_TAG
30   * @returns { boolean } Returns true if init success, otherwise returns false.
31   * @syscap SystemCapability.Communication.ConnectedTag
32   * @since 8
33   * @deprecated since 9
34   * @useinstead ohos.connectedTag/connectedTag#initialize
35   */
36  function init(): boolean;
37
38  /**
39   * Initializes the connected NFC tag.
40   *
41   * @permission ohos.permission.NFC_TAG
42   * @throws { BusinessError } 201 - Permission denied.
43   * @throws { BusinessError } 801 - Capability not supported.
44   * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service.
45   * @syscap SystemCapability.Communication.ConnectedTag
46   * @since 9
47   */
48  function initialize(): void;
49
50  /**
51   * UnInitializes Connected Tag.
52   *
53   * @permission ohos.permission.NFC_TAG
54   * @returns { boolean } Returns true if uninit success, otherwise returns false.
55   * @syscap SystemCapability.Communication.ConnectedTag
56   * @since 8
57   * @deprecated since 9
58   * @useinstead ohos.connectedTag/connectedTag#uninitialize
59   */
60  function uninit(): boolean;
61
62  /**
63   * Uninitializes the connected NFC tag.
64   *
65   * @permission ohos.permission.NFC_TAG
66   * @throws { BusinessError } 201 - Permission denied.
67   * @throws { BusinessError } 801 - Capability not supported.
68   * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service.
69   * @syscap SystemCapability.Communication.ConnectedTag
70   * @since 9
71   */
72  function uninitialize(): void;
73
74  /**
75   * Reads the NDEF Data.
76   *
77   * @permission ohos.permission.NFC_TAG
78   * @returns { Promise<string> } Returns the NDEF Data.
79   * @syscap SystemCapability.Communication.ConnectedTag
80   * @since 8
81   * @deprecated since 9
82   * @useinstead ohos.connectedTag/connectedTag#read
83   */
84  function readNdefTag(): Promise<string>;
85
86  /**
87   * Reads the NDEF Data.
88   *
89   * @permission ohos.permission.NFC_TAG
90   * @param { AsyncCallback<string> } callback
91   * @syscap SystemCapability.Communication.ConnectedTag
92   * @since 8
93   * @deprecated since 9
94   * @useinstead ohos.connectedTag/connectedTag#read
95   */
96  function readNdefTag(callback: AsyncCallback<string>): void;
97
98  /**
99   * Reads the NDEF data from the connected NFC tag.
100   *
101   * @permission ohos.permission.NFC_TAG
102   * @returns { Promise<number[]> } The reponse NDEF data.
103   * @throws { BusinessError } 201 - Permission denied.
104   * @throws { BusinessError } 801 - Capability not supported.
105   * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service.
106   * @syscap SystemCapability.Communication.ConnectedTag
107   * @since 9
108   */
109  function read(): Promise<number[]>;
110
111  /**
112   * Reads the NDEF data from the connected NFC tag.
113   *
114   * @permission ohos.permission.NFC_TAG
115   * @param { AsyncCallback<number[]> } callback The callback to receive the data.
116   * @throws { BusinessError } 201 - Permission denied.
117   * @throws { BusinessError } 801 - Capability not supported.
118   * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service.
119   * @syscap SystemCapability.Communication.ConnectedTag
120   * @since 9
121   */
122  function read(callback: AsyncCallback<number[]>): void;
123
124  /**
125   * Writes the NDEF Data.
126   *
127   * @permission ohos.permission.NFC_TAG
128   * @param { string } data The Data to write.
129   * @returns { Promise<void> } The void.
130   * @syscap SystemCapability.Communication.ConnectedTag
131   * @since 8
132   * @deprecated since 9
133   * @useinstead ohos.connectedTag/connectedTag#write
134   */
135  function writeNdefTag(data: string): Promise<void>;
136
137  /**
138   * Writes the NDEF Data.
139   *
140   * @permission ohos.permission.NFC_TAG
141   * @param { string } data The Data to write.
142   * @param { AsyncCallback<void> } callback
143   * @syscap SystemCapability.Communication.ConnectedTag
144   * @since 8
145   * @deprecated since 9
146   * @useinstead ohos.connectedTag/connectedTag#write
147   */
148  function writeNdefTag(data: string, callback: AsyncCallback<void>): void;
149
150  /**
151   * Writes the NDEF data to the connected NFC tag.
152   *
153   * @permission ohos.permission.NFC_TAG
154   * @param { number[] } data Indicates the NDEF data to send, which is a byte array.
155   * @returns { Promise<void> } The void.
156   * @throws { BusinessError } 201 - Permission denied.
157   * @throws { BusinessError } 401 - The parameter check failed.
158   * @throws { BusinessError } 801 - Capability not supported.
159   * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service.
160   * @syscap SystemCapability.Communication.ConnectedTag
161   * @since 9
162   */
163  function write(data: number[]): Promise<void>;
164
165  /**
166   * Writes the NDEF data to the connected NFC tag.
167   *
168   * @permission ohos.permission.NFC_TAG
169   * @param { number[] } data Indicates the NDEF data to send, which is a byte array.
170   * @param { AsyncCallback<void> } callback
171   * @throws { BusinessError } 201 - Permission denied.
172   * @throws { BusinessError } 401 - The parameter check failed.
173   * @throws { BusinessError } 801 - Capability not supported.
174   * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service.
175   * @syscap SystemCapability.Communication.ConnectedTag
176   * @since 9
177   */
178  function write(data: number[], callback: AsyncCallback<void>): void;
179
180  /**
181   * Subscribes NFC RF status change events.
182   *
183   * @permission ohos.permission.NFC_TAG
184   * @param {'notify'} type The callback type.
185   * @param { Callback<number> } callback The callback function to be registered.
186   * @syscap SystemCapability.Communication.ConnectedTag
187   * @since 8
188   */
189  function on(type: 'notify', callback: Callback<number>): void;
190
191  /**
192   * Unsubscribes NFC RF status change events.
193   * <p>All callback functions will be unregistered If there is no specific callback parameter.</p>
194   *
195   * @permission ohos.permission.NFC_TAG
196   * @param { 'notify' } type The callback type.
197   * @param { Callback<number> } callback The callback function to be unregistered.
198   * @syscap SystemCapability.Communication.ConnectedTag
199   * @since 8
200   */
201  function off(type: 'notify', callback?: Callback<number>): void;
202
203  /**
204   * Describes the NFC RF type.
205   *
206   * @enum { number }
207   * @syscap SystemCapability.Communication.ConnectedTag
208   * @since 8
209   */
210  enum NfcRfType {
211    /**
212     * NFC RF LEAVE
213     *
214     * @syscap SystemCapability.Communication.ConnectedTag
215     * @since 8
216     */
217    NFC_RF_LEAVE = 0,
218
219    /**
220     * NFC RF ENTER
221     *
222     * @syscap SystemCapability.Communication.ConnectedTag
223     * @since 8
224     */
225    NFC_RF_ENTER = 1
226  }
227}
228
229export default connectedTag;
230