• 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 { AsyncCallback, Callback } from './basic';
17
18/**
19 * Provides methods to operate or manage Connected Tag.
20 *
21 * @since 8
22 * @syscap SystemCapability.Communication.ConnectedTag
23 */
24declare namespace connectedTag {
25    /**
26     * Initializes Connected Tag.
27     *
28     * @returns Returns true or false.
29     * @permission ohos.permission.NFC_TAG
30     * @since 8
31     * @deprecated since 9
32     * @useinstead ohos.connectedTag/connectedTag#initialize
33     */
34    function init(): boolean;
35
36    /**
37     * Initializes the connected NFC tag.
38     *
39     * @throws { BusinessError } 201 - Permission denied.
40     * @throws { BusinessError } 801 - Capability not supported.
41     * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service.
42     * @permission ohos.permission.NFC_TAG
43     * @since 9
44     */
45    function initialize(): void;
46
47    /**
48     * UnInitializes Connected Tag.
49     *
50     * @returns Returns true or false.
51     * @permission ohos.permission.NFC_TAG
52     * @since 8
53     * @deprecated since 9
54     * @useinstead ohos.connectedTag/connectedTag#uninitialize
55     */
56    function uninit(): boolean;
57
58    /**
59     * Uninitializes the connected NFC tag.
60     *
61     * @throws { BusinessError } 201 - Permission denied.
62     * @throws { BusinessError } 801 - Capability not supported.
63     * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service.
64     * @permission ohos.permission.NFC_TAG
65     * @since 9
66     */
67    function uninitialize(): void;
68
69    /**
70     * Reads the NDEF Data.
71     *
72     * @returns Returns the NDEF Data.
73     * @permission ohos.permission.NFC_TAG
74     * @since 8
75     * @deprecated since 9
76     * @useinstead ohos.connectedTag/connectedTag#read
77     */
78    function readNdefTag(): Promise<string>;
79    function readNdefTag(callback: AsyncCallback<string>): void;
80
81    /**
82     * Reads the NDEF data from the connected NFC tag.
83     *
84     * @returns The reponse NDEF data.
85     * @throws { BusinessError } 201 - Permission denied.
86     * @throws { BusinessError } 801 - Capability not supported.
87     * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service.
88     * @permission ohos.permission.NFC_TAG
89     * @since 9
90     */
91    function read(): Promise<number[]>;
92    function read(callback: AsyncCallback<number[]>): void;
93
94    /**
95     * Writes the NDEF Data.
96     *
97     * @param data The Data to write.
98     * @returns Returns true or false.
99     * @permission ohos.permission.NFC_TAG
100     * @since 8
101     * @deprecated since 9
102     * @useinstead ohos.connectedTag/connectedTag#write
103     */
104    function writeNdefTag(data: string): Promise<void>;
105    function writeNdefTag(data: string, callback: AsyncCallback<void>): void;
106
107    /**
108     * Writes the NDEF data to the connected NFC tag.
109     *
110     * @param data Indicates the NDEF data to send, which is a byte array.
111     * @throws { BusinessError } 201 - Permission denied.
112     * @throws { BusinessError } 401 - The parameter check failed.
113     * @throws { BusinessError } 801 - Capability not supported.
114     * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service.
115     * @permission ohos.permission.NFC_TAG
116     * @since 9
117     */
118    function write(data: number[]): Promise<void>;
119    function write(data: number[], callback: AsyncCallback<void>): void;
120
121    /**
122     * Subscribes NFC RF status change events.
123     *
124     * @type The callback type.
125     * @param callback The callback function to be registered.
126     * @returns Returns NFC_RF_LEAVE or NFC_RF_ENTER
127     * @permission ohos.permission.NFC_TAG
128     * @since 8
129     */
130    function on(type: "notify", callback: Callback<number>): void;
131
132    /**
133     * Unsubscribes NFC RF status change events.
134     *
135     * <p>All callback functions will be unregistered If there is no specific callback parameter.</p>
136     *
137     * @type The callback type.
138     * @param callback The callback function to be unregistered.
139     * @permission ohos.permission.NFC_TAG
140     * @since 8
141     */
142    function off(type: "notify", callback?:Callback<number>): void;
143
144    /**
145     * Describes the NFC RF type.
146     *
147     * @since 8
148     */
149    enum NfcRfType {
150        /** NFC RF LEAVE */
151        NFC_RF_LEAVE = 0,
152
153        /** NFC RF ENTER */
154        NFC_RF_ENTER = 1,
155    }
156}
157
158export default connectedTag;
159