diff --git a/en/react-native-touch-id.md b/en/react-native-touch-id.md index 7eeda52e42917ed03e24152b2f807edfb5b56330..8ef313bf0a0eaabebe7d5a3078e49037d825eaa2 100644 --- a/en/react-native-touch-id.md +++ b/en/react-native-touch-id.md @@ -14,17 +14,18 @@ > [!TIP] [GitHub address](https://github.com/react-native-oh-library/react-native-touch-id) -## Installation and Usage -Please refer to the Releases page of the third-party library for the corresponding version information +The repository for this third-party library has been migrated to Gitcode, and it now supports direct download from npm. The new package name is: `@react-native-ohos/react-native-touch-id`. The specific version relationships are as follows: + +| Version | Package Name | Repository | Release |Supported RN Version | +| ------------------------------ | ---------------- | ------------------- | ------------------- | -------------------- | +| <= 4.4.1-0.0.3@deprecated | @react-native-oh-tpl/react-native-touch-id | [Github](https://github.com/react-native-oh-library/react-native-touch-id) | [Github Releases](https://github.com/react-native-oh-library/react-native-touch-id/releases) | 0.72 | +| 4.4.1 | @react-native-ohos/react-native-touch-id | [GitCode](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id) | [GitCode Releases]() | 0.72 | +| 4.5.0 | @react-native-ohos/react-native-touch-id | [GitCode](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id) | [GitCode Releases]() | 0.77 | -| Third-party Library Version | Release Information | Supported RN Version | -|-------| ------------------------------------------------------------ | ---------- | -| 4.4.1@deprecated | [@react-native-oh-tpl/react-native-touch-id Releases(deprecated)](https://github.com/react-native-oh-library/react-native-touch-id/releases) | 0.72 | -| 4.4.2 | [@react-native-ohos/react-native-touch-id Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/releases) | 0.72 | -| 4.5.0 | [@react-native-ohos/react-native-touch-id Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/releases) | 0.77 | +## Installation and Usage -For older versions not published on npm, please refer to the [Installation Guide](/zh-cn/tgz-usage.md) to install the tgz package. +For older versions not published on npm, please refer to the [Installation Guide](/en/tgz-usage-en.md) to install the tgz package. Go to the project directory and execute the following instruction: @@ -141,8 +142,68 @@ Method 2: Directly link to the source code. > [!TIP] For details, see [Directly Linking Source Code](/en/link-source-code.md). +### 3. Configuring CMakeLists and Introducing TouchIdPackage + +> If you are using version <= 4.4.1-0.0.3, please skip this chapter. + +Open `entry/src/main/cpp/CMakeLists.txt` and add the following code: + +```diff +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_BEGIN: manual_package_linking_1 +add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-touch-id/src/main/cpp" ./touch_id) +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") + +add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) ++ target_link_libraries(rnoh_app PUBLIC rnoh_touch_id) +# RNOH_END: manual_package_linking_2 +``` -### 3. Introducing TouchIdPackage to ArkTS +Open `entry/src/main/cpp/PackageProvider.cpp` and add the following code: + +```diff +#include "RNOH/PackageProvider.h" +#include "generated/RNOHGeneratedPackage.h" +#include "SamplePackage.h" ++ #include "TouchIdPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), + std::make_shared(ctx), ++ std::make_shared(ctx) + }; +} +``` + +### 4. Introducing TouchIdPackage to ArkTS Open the `entry/src/main/ets/RNPackagesFactory.ts` file and add the following code: @@ -158,7 +219,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] { } ``` -### 4. Running +### 5. Running Click the `sync` button in the upper right corner. @@ -178,13 +239,11 @@ Then build and run the code. To use this repository, you need to use the correct React-Native and RNOH versions. In addition, you need to use DevEco Studio and the ROM on your phone. -Please refer to the Releases page of the third-party library for the corresponding version information +Verified in the following versions. -| Third-party Library Version | Release Information | Supported RN Version | -|-------| ------------------------------------------------------------ | ---------- | -| 4.4.1@deprecated | [@react-native-oh-tpl/react-native-touch-id Releases(deprecated)](https://github.com/react-native-oh-library/react-native-touch-id/releases) | 0.72 | -| 4.4.2 | [@react-native-ohos/react-native-touch-id Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/releases) | 0.72 | -| 4.5.0 | [@react-native-ohos/react-native-touch-id Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/releases) | 0.77 | +1. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; +2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio: 5.0.3.900; ROM: Next.0.0.71; +3. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; ### Permission Requirements @@ -212,6 +271,27 @@ In your `module.json5` | ---- | ----------- | ---- | -------- | -------- | ------------------ | | isSupported | Whether touchid is supported | function | yes | ios/andriod | yes | | authenticate | Verify touchid | function | yes | ios/andriod | yes | +## API Parameters Introduction +### authenticate(reason?: string, config?: AuthenticateConfig); +* **reason**: A string providing a clear reason for requesting authentication +* **config**: A configuration object for more detailed dialog settings + * **AuthenticateConfig**: + | Name | Description | Type | Required | Platform | HarmonyOS Support | + | ---- | ----------- | ---- | -------- | -------- | ------------------ | + | title | **Android only** - Title of the confirmation dialog | string | no | ios/android | yes | + | imageColor | **Android only** - Color of the fingerprint image | string | no | ios/android | no | + | imageErrorColor | **Android only** - Color of the fingerprint image after a failed attempt | string | no | ios/android | no | + | sensorDescription | **Android only** - Text displayed next to the fingerprint image | string | no | ios/android | no | + | sensorErrorDescription | **Android only** - Text displayed next to the fingerprint image after a failed attempt | string | no | ios/android | no | + | cancelText | **Android only** - Cancel button text | string | no | ios/android | yes | + | fallbackLabel | **iOS only** - By default shows "Show Password" label. If set to empty string, the label will be invisible | string | no | ios/android | no | + | passcodeFallback | **iOS only** - Defaults to false. If set to true, will allow fallback to passcode | boolean | no | ios/android | no | +### isSupported(config?: IsSupportedConfig): `Promise`; +* **config** - Returns a `Promise` that rejects if TouchID is not supported. On iOS, resolves to a `biometryType` string with value `FaceID` or `TouchID` + * **IsSupportedConfig**: + | Name | Description | Type | Required | Platform | HarmonyOS Support | + | ---- | ----------- | ---- | -------- | -------- | ------------------ | + | unifiedErrors| Returns unified error messages | boolean | no | ios/android | yes | ## Properties > [!TIP] The **Platform** column indicates the platform where the properties are supported in the original third-party library. @@ -222,22 +302,25 @@ In your `module.json5` | Name | Description | Type | Required | Platform | HarmonyOS Support | | ---- | ----------- | ---- | -------- | -------- | ------------------ | -| Touch ID Error | Permission verification failed | string | no | harmonry | yes | -| Touch ID Error | Incorrect parameters | string | no | harmonry | yes | -| Touch ID Error | Authentication failed | string | no | harmonry | yes | -| Touch ID Error | The operation is canceled | string | no | harmonry | yes | -| Touch ID Error | The operation is time-out | string | no | harmonry | yes | -| Touch ID Error | The authentication type is not supported | string | no | harmonry | yes | -| Touch ID Error | The authentication trust level is not supported | string | no | harmonry | yes | -| Touch ID Error | The authentication task is busy | string | no | harmonry | yes | -| Touch ID Error | The authenticator is locked | string | no | harmonry | yes | -| Touch ID Error | General operation error | string | no | harmonry | no | -| Touch ID Error | The authentication type is not supported | string | no | harmonry | yes | -| Touch ID Error | The type of credential has not been enrolled | string | no | harmonry | yes | -| Touch ID Error | The authentication is canceled from widget's navigation button | string | no | harmonry | yes | -| Touch ID Error | Indicates that current authentication failed because of PIN expired | string | no | harmonry | yes | +| 201 | Permission verification failed | string | no | harmonry | yes | +| 401 | Incorrect parameters | string | no | harmonry | no | +| 12500001 | Authentication failed | string | no | harmonry | yes | +| 12500002 | General operation error | string | no | harmonry | no | +| 12500003 | The operation is canceled | string | no | harmonry | yes | +| 12500004 | The operation is time-out | string | no | harmonry | no | +| 12500005 | The authentication type is not supported | string | no | harmonry | no | +| 12500006 | The authentication trust level is not supported | string | no | harmonry | no | +| 12500007 | The authentication task is busy | string | no | harmonry | no | +| 12500009 | The authenticator is locked | string | no | harmonry | yes | +| 12500010 | The type of credential has not been enrolled | string | no | harmonry | yes | +| 12500011 | The authentication is canceled from widget's navigation button | string | no | harmonry | yes | +| 12500013 | Indicates that current authentication failed because of PIN expired | string | no | harmonry | no | + ## Known Issues +- [ ] The config parameter is partially supported.[issue#13](https://github.com/react-native-oh-library/react-native-touch-id/issues/13) +- [ ] Error is partially supported.[issue#12](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/issues/12) + ## Others ## License diff --git a/zh-cn/react-native-touch-id.md b/zh-cn/react-native-touch-id.md index 4307dfbf5565ad228ba198786159e881edb422a3..b78734bd83ab59fcadc8a8da181c2516f7eef005 100644 --- a/zh-cn/react-native-touch-id.md +++ b/zh-cn/react-native-touch-id.md @@ -14,15 +14,15 @@ > [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-touch-id) -## 安装与使用 +该第三方库的仓库已迁移至 Gitcode,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/react-native-touch-id`,具体版本所属关系如下: -请到三方库的 Releases 发布地址查看配套的版本信息: +| Version | Package Name | Repository | Release |Supported RN Version | +| ------------------------------ | ---------------- | ------------------- | ------------------- | -------------------- | +| <= 4.4.1-0.0.3@deprecated | @react-native-oh-tpl/react-native-touch-id | [Github](https://github.com/react-native-oh-library/react-native-touch-id) | [Github Releases](https://github.com/react-native-oh-library/react-native-touch-id/releases) | 0.72 | +| 4.4.2 | @react-native-ohos/react-native-touch-id | [GitCode](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id) | [GitCode Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/releases) | 0.72 | +| 4.5.0 | @react-native-ohos/react-native-touch-id | [GitCode](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id) | [GitCode Releases]() | 0.77 | -| 三方库版本 | 发布信息 | 支持RN版本 | -|-------| ------------------------------------------------------------ | ---------- | -| 4.4.1@deprecated | [@react-native-oh-tpl/react-native-touch-id Releases(deprecated)](https://github.com/react-native-oh-library/react-native-touch-id/releases) | 0.72 | -| 4.4.2 | [@react-native-ohos/react-native-touch-id Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/releases) | 0.72 | -| 4.5.0 | [@react-native-ohos/react-native-touch-id Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/releases) | 0.77 | +## 安装与使用 对于未发布到npm的旧版本,请参考[安装指南](/zh-cn/tgz-usage.md)安装tgz包。 @@ -142,7 +142,69 @@ ohpm install > [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](/zh-cn/link-source-code.md) -### 3.在 ArkTs 侧引入 TouchIdPackage +### 3.配置 CMakeLists 和引入 TouchIdPackage + +> 若使用的是 <= 4.4.1-0.0.3 版本,请跳过本章。 + +打开 `entry/src/main/cpp/CMakeLists.txt`,添加: + +```diff +project(rnapp) +cmake_minimum_required(VERSION 3.4.1) +set(CMAKE_SKIP_BUILD_RPATH TRUE) +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp") +set(LOG_VERBOSITY_LEVEL 1) +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments") +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie") +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use +add_compile_definitions(WITH_HITRACE_SYSTRACE) + +add_subdirectory("${RNOH_CPP_DIR}" ./rn) + +# RNOH_BEGIN: manual_package_linking_1 +add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package) ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-touch-id/src/main/cpp" ./touch_id) + +# RNOH_END: manual_package_linking_1 + +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp") + +add_library(rnoh_app SHARED + ${GENERATED_CPP_FILES} + "./PackageProvider.cpp" + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" +) +target_link_libraries(rnoh_app PUBLIC rnoh) + +# RNOH_BEGIN: manual_package_linking_2 +target_link_libraries(rnoh_app PUBLIC rnoh_sample_package) ++ target_link_libraries(rnoh_app PUBLIC rnoh_touch_id) +# RNOH_END: manual_package_linking_2 +``` + +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加: + +```diff +#include "RNOH/PackageProvider.h" +#include "generated/RNOHGeneratedPackage.h" +#include "SamplePackage.h" ++ #include "TouchIdPackage.h" + +using namespace rnoh; + +std::vector> PackageProvider::getPackages(Package::Context ctx) { + return { + std::make_shared(ctx), + std::make_shared(ctx), ++ std::make_shared(ctx) + }; +} +``` + +### 4.在 ArkTs 侧引入 TouchIdPackage 打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加: @@ -158,7 +220,7 @@ export function createRNPackages(ctx: RNPackageContext): RNPackage[] { } ``` -### 4.运行 +### 5.运行 点击右上角的 `sync` 按钮 @@ -175,16 +237,13 @@ ohpm install ### 兼容性 - 要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。 -请到三方库的 Releases 发布地址查看配套的版本信息: +在以下版本验证通过: -| 三方库版本 | 发布信息 | 支持RN版本 | -|-------| ------------------------------------------------------------ | ---------- | -| 4.4.1@deprecated | [@react-native-oh-tpl/react-native-touch-id Releases(deprecated)](https://github.com/react-native-oh-library/react-native-touch-id/releases) | 0.72 | -| 4.4.2 | [@react-native-ohos/react-native-touch-id Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/releases) | 0.72 | -| 4.5.0 | [@react-native-ohos/react-native-touch-id Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/releases) | 0.77 | +1. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; +2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio: 5.0.3.900; ROM: Next.0.0.71; +3. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112; ### 权限要求 @@ -210,8 +269,30 @@ In your `module.json5` | Name | Description | Type | Required | Platform | HarmonyOS Support | | ---- | ----------- | ---- | -------- | -------- | ------------------ | -| isSupported | Whether touchid is supported | function | yes | ios/andriod | yes | -| authenticate | Verify touchid | function | yes | ios/andriod | yes | +| isSupported | 是否支持 Touch ID | function | yes | ios/andriod | yes | +| authenticate | 验证 Touch ID | function | yes | ios/andriod | yes | + +## API 参数介绍 +### authenticate(reason?: string, config?: AuthenticateConfig); +* **reason**: 提供请求身份验证的明确原因的字符串 +* **config**: 用于更详细对话框设置的配置对象 + * **AuthenticateConfig**: + | Name | Description | Type | Required | Platform | HarmonyOS Support | + | ---- | ----------- | ---- | -------- | -------- | ------------------ | + | title | **仅Android** - 确认对话框的标题 | string | no | ios/andriod | yes | + | imageColor | **仅Android** - 指纹图像的颜色 | string | no | ios/andriod | no | + | imageErrorColor | **仅Android** - 尝试失败后指纹图像的颜色 | string | no | ios/andriod | no | + | sensorDescription | **仅Android** - 指纹图像旁边显示的文字 | string | no | ios/andriod | no | + | sensorErrorDescription | **仅Android** - 尝试失败后指纹图像旁边显示的文字 | string | no | ios/andriod | no | + | cancelText | **仅Android** - 取消按钮文字 | string | no | ios/andriod | yes | + | fallbackLabel | **仅iOS** - 默认显示"显示密码"标签。如果设置为空字符串,标签将不可见 | string | no | ios/andriod | no | + | passcodeFallback | **仅iOS** - 默认设置为false。如果设置为true,将允许使用键盘密码 | boolean | no | ios/andriod | no | +### isSupported(config?: IsSupportedConfig): `Promise`; +* **config** - 返回一个`Promise`,如果TouchID不支持则会拒绝。在iOS上会解析为一个`biometryType`字符串,值为`FaceID`或`TouchID` + * **IsSupportedConfig**: + | Name | Description | Type | Required | Platform | HarmonyOS Support | + | ---- | ----------- | ---- | -------- | -------- | ------------------ | + | unifiedErrors| 返回统一的错误信息 |boolean| no | ios/andriod | yes | ## 属性 > [!TIP] "Platform"列表示该属性在原三方库上支持的平台。 @@ -222,22 +303,25 @@ In your `module.json5` | Name | Description | Type | Required | Platform | HarmonyOS Support | | ---- | ----------- | ---- | -------- | -------- | ------------------ | -| Touch ID Error | Permission verification failed | string | no | harmonry | yes | -| Touch ID Error | Incorrect parameters | string | no | harmonry | yes | -| Touch ID Error | Authentication failed | string | no | harmonry | yes | -| Touch ID Error | The operation is canceled | string | no | harmonry | yes | -| Touch ID Error | The operation is time-out | string | no | harmonry | yes | -| Touch ID Error | The authentication type is not supported | string | no | harmonry | yes | -| Touch ID Error | The authentication trust level is not supported | string | no | harmonry | yes | -| Touch ID Error | The authentication task is busy | string | no | harmonry | yes | -| Touch ID Error | The authenticator is locked | string | no | harmonry | yes | -| Touch ID Error | General operation error | string | no | harmonry | no | -| Touch ID Error | The authentication type is not supported | string | no | harmonry | yes | -| Touch ID Error | The type of credential has not been enrolled | string | no | harmonry | yes | -| Touch ID Error | The authentication is canceled from widget's navigation button | string | no | harmonry | yes | -| Touch ID Error | Indicates that current authentication failed because of PIN expired | string | no | harmonry | yes | +| 201 | Permission verification failed | string | no | harmonry | yes | +| 401 | Incorrect parameters | string | no | harmonry | no | +| 12500001 | Authentication failed | string | no | harmonry | yes | +| 12500002 | General operation error | string | no | harmonry | no | +| 12500003 | The operation is canceled | string | no | harmonry | yes | +| 12500004 | The operation is time-out | string | no | harmonry | no | +| 12500005 | The authentication type is not supported | string | no | harmonry | no | +| 12500006 | The authentication trust level is not supported | string | no | harmonry | no | +| 12500007 | The authentication task is busy | string | no | harmonry | no | +| 12500009 | The authenticator is locked | string | no | harmonry | yes | +| 12500010 | The type of credential has not been enrolled | string | no | harmonry | yes | +| 12500011 | The authentication is canceled from widget's navigation button | string | no | harmonry | yes | +| 12500013 | Indicates that current authentication failed because of PIN expired | string | no | harmonry | no | + ## 遗留问题 +- [ ] config参数部分支持.[issue#13](https://github.com/react-native-oh-library/react-native-touch-id/issues/13) +- [ ] error部分触发。[issue#12](https://gitcode.com/openharmony-sig/rntpc_react-native-touch-id/issues/12) + ## 其他 ## 开源协议