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 16/** 17 * @file 18 * @kit ConnectivityKit 19 */ 20 21import type { AsyncCallback, BusinessError, Callback } from './@ohos.base'; 22 23/** 24 * Provides methods to operate or manage Connected Tag. 25 * 26 * @namespace connectedTag 27 * @syscap SystemCapability.Communication.ConnectedTag 28 * @since 8 29 */ 30declare namespace connectedTag { 31 /** 32 * Initializes Connected Tag. 33 * 34 * @permission ohos.permission.NFC_TAG 35 * @returns { boolean } Returns true if init success, otherwise returns false. 36 * @syscap SystemCapability.Communication.ConnectedTag 37 * @since 8 38 * @deprecated since 9 39 * @useinstead ohos.connectedTag/connectedTag#initialize 40 */ 41 function init(): boolean; 42 43 /** 44 * Initializes the connected NFC tag. 45 * 46 * @permission ohos.permission.NFC_TAG 47 * @throws { BusinessError } 201 - Permission denied. 48 * @throws { BusinessError } 801 - Capability not supported. 49 * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service. 50 * @syscap SystemCapability.Communication.ConnectedTag 51 * @since 9 52 */ 53 function initialize(): void; 54 55 /** 56 * UnInitializes Connected Tag. 57 * 58 * @permission ohos.permission.NFC_TAG 59 * @returns { boolean } Returns true if uninit success, otherwise returns false. 60 * @syscap SystemCapability.Communication.ConnectedTag 61 * @since 8 62 * @deprecated since 9 63 * @useinstead ohos.connectedTag/connectedTag#uninitialize 64 */ 65 function uninit(): boolean; 66 67 /** 68 * Uninitializes the connected NFC tag. 69 * 70 * @permission ohos.permission.NFC_TAG 71 * @throws { BusinessError } 201 - Permission denied. 72 * @throws { BusinessError } 801 - Capability not supported. 73 * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service. 74 * @syscap SystemCapability.Communication.ConnectedTag 75 * @since 9 76 */ 77 function uninitialize(): void; 78 79 /** 80 * Reads the NDEF Data. 81 * 82 * @permission ohos.permission.NFC_TAG 83 * @returns { Promise<string> } Returns the NDEF Data. 84 * @syscap SystemCapability.Communication.ConnectedTag 85 * @since 8 86 * @deprecated since 9 87 * @useinstead ohos.connectedTag/connectedTag#read 88 */ 89 function readNdefTag(): Promise<string>; 90 91 /** 92 * Reads the NDEF Data. 93 * 94 * @permission ohos.permission.NFC_TAG 95 * @param { AsyncCallback<string> } callback 96 * @syscap SystemCapability.Communication.ConnectedTag 97 * @since 8 98 * @deprecated since 9 99 * @useinstead ohos.connectedTag/connectedTag#read 100 */ 101 function readNdefTag(callback: AsyncCallback<string>): void; 102 103 /** 104 * Reads the NDEF data from the connected NFC tag. 105 * 106 * @permission ohos.permission.NFC_TAG 107 * @returns { Promise<number[]> } The reponse NDEF data. 108 * @throws { BusinessError } 201 - Permission denied. 109 * @throws { BusinessError } 801 - Capability not supported. 110 * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service. 111 * @syscap SystemCapability.Communication.ConnectedTag 112 * @since 9 113 */ 114 function read(): Promise<number[]>; 115 116 /** 117 * Reads the NDEF data from the connected NFC tag. 118 * 119 * @permission ohos.permission.NFC_TAG 120 * @param { AsyncCallback<number[]> } callback The callback to receive the data. 121 * @throws { BusinessError } 201 - Permission denied. 122 * @throws { BusinessError } 801 - Capability not supported. 123 * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service. 124 * @syscap SystemCapability.Communication.ConnectedTag 125 * @since 9 126 */ 127 function read(callback: AsyncCallback<number[]>): void; 128 129 /** 130 * Writes the NDEF Data. 131 * 132 * @permission ohos.permission.NFC_TAG 133 * @param { string } data The Data to write. 134 * @returns { Promise<void> } The void. 135 * @syscap SystemCapability.Communication.ConnectedTag 136 * @since 8 137 * @deprecated since 9 138 * @useinstead ohos.connectedTag/connectedTag#write 139 */ 140 function writeNdefTag(data: string): Promise<void>; 141 142 /** 143 * Writes the NDEF Data. 144 * 145 * @permission ohos.permission.NFC_TAG 146 * @param { string } data The Data to write. 147 * @param { AsyncCallback<void> } callback 148 * @syscap SystemCapability.Communication.ConnectedTag 149 * @since 8 150 * @deprecated since 9 151 * @useinstead ohos.connectedTag/connectedTag#write 152 */ 153 function writeNdefTag(data: string, callback: AsyncCallback<void>): void; 154 155 /** 156 * Writes the NDEF data to the connected NFC tag. 157 * 158 * @permission ohos.permission.NFC_TAG 159 * @param { number[] } data Indicates the NDEF data to send, which is a byte array. 160 * @returns { Promise<void> } The void. 161 * @throws { BusinessError } 201 - Permission denied. 162 * @throws { BusinessError } 401 - The parameter check failed. Possible causes: 163 * <br> 1. Mandatory parameters are left unspecified. 164 * <br> 2. Incorrect parameters types. 165 * <br> 3. Parameter verification failed. 166 * @throws { BusinessError } 801 - Capability not supported. 167 * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service. 168 * @syscap SystemCapability.Communication.ConnectedTag 169 * @since 9 170 */ 171 function write(data: number[]): Promise<void>; 172 173 /** 174 * Writes the NDEF data to the connected NFC tag. 175 * 176 * @permission ohos.permission.NFC_TAG 177 * @param { number[] } data Indicates the NDEF data to send, which is a byte array. 178 * @param { AsyncCallback<void> } callback 179 * @throws { BusinessError } 201 - Permission denied. 180 * @throws { BusinessError } 401 - The parameter check failed. Possible causes: 181 * <br> 1. Mandatory parameters are left unspecified. 182 * <br> 2. Incorrect parameters types. 183 * <br> 3. Parameter verification failed. 184 * @throws { BusinessError } 801 - Capability not supported. 185 * @throws { BusinessError } 3200101 - Connected NFC tag running state is abnormal in service. 186 * @syscap SystemCapability.Communication.ConnectedTag 187 * @since 9 188 */ 189 function write(data: number[], callback: AsyncCallback<void>): void; 190 191 /** 192 * Subscribes NFC RF status change events. 193 * 194 * @permission ohos.permission.NFC_TAG 195 * @param {'notify'} type The callback type. 196 * @param { Callback<number> } callback The callback function to be registered. 197 * @syscap SystemCapability.Communication.ConnectedTag 198 * @since 8 199 */ 200 function on(type: 'notify', callback: Callback<number>): void; 201 202 /** 203 * Unsubscribes NFC RF status change events. 204 * <p>All callback functions will be unregistered If there is no specific callback parameter.</p> 205 * 206 * @permission ohos.permission.NFC_TAG 207 * @param { 'notify' } type The callback type. 208 * @param { Callback<number> } callback The callback function to be unregistered. 209 * @syscap SystemCapability.Communication.ConnectedTag 210 * @since 8 211 */ 212 function off(type: 'notify', callback?: Callback<number>): void; 213 214 /** 215 * Describes the NFC RF type. 216 * 217 * @enum { number } 218 * @syscap SystemCapability.Communication.ConnectedTag 219 * @since 8 220 */ 221 enum NfcRfType { 222 /** 223 * NFC RF LEAVE 224 * 225 * @syscap SystemCapability.Communication.ConnectedTag 226 * @since 8 227 */ 228 NFC_RF_LEAVE = 0, 229 230 /** 231 * NFC RF ENTER 232 * 233 * @syscap SystemCapability.Communication.ConnectedTag 234 * @since 8 235 */ 236 NFC_RF_ENTER = 1 237 } 238} 239 240export default connectedTag; 241