跳到主要内容

安装

安装包

1. 配置 npm registry

在项目根目录创建 .npmrc 文件:

@qitech:registry=https://registry.npmjs.org/
//registry.npmjs.org/:_authToken=NPM_TOKEN_SENT_BY_QI_TECH

请将 NPM_TOKEN_SENT_BY_QI_TECH 替换为支持团队提供的 token。如果您尚未收到 token,请联系 suporte.caas@qitech.com.br

2. 安装依赖

yarn add @qitech/react-native-device-scan

3. 导入

import {
CAAS_ENVIRONMENT,
startDeviceScan,
} from '@qitech/react-native-device-scan';

Android 配置

1. QI Tech Maven 仓库

在项目级 build.gradle 中添加 QI Tech 的 Maven 仓库:

allprojects {
repositories {
maven { url 'https://sdks.qitech.com.br/' }
...
}
}

2. AdMob

AndroidManifest.xml 中添加以下代码以初始化 AdMob 服务:

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="<ADMOB_APP_ID>"/>

如果您还没有 ADMOB_APP_ID,请联系 suporte.caas@qitech.com.br

3. 权限

AndroidManifest.xml 中声明您希望向 SDK 开放的权限。完整列表参见权限

iOS 配置

1. QI Tech iOS 仓库 source

Podfile 顶部添加以下 source:

source 'https://cdn.cocoapods.org/'
source 'https://github.com/QITechSDKs/iOS.git'

2. 静态 framework

在使用 低于 26 版本 的 Xcode 时需要:

use_frameworks! :linkage => :static
注意

Flipper 无法与 use_frameworks! 共存。如果 Podfile 中存在 use_flipper() 调用,请将其移除。

3. 模块稳定性

Datadog 依赖要求启用 BUILD_LIBRARY_FOR_DISTRIBUTION。请添加下面的 post_install 代码块(或合并到已有的 post_install 中):

post_install do |installer|
installer.pods_project.targets.each do |target|
if ['DatadogCore', 'DatadogInternal', 'DatadogCrashReporting', 'DatadogLogs'].include?(target.name)
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '15.5'
config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
end
end
end
end

4. 权限

Info.plist 中声明您希望向 SDK 开放的权限。参见权限

5. 安装 pod

cd ios && pod install

Expo 配置

该包内置了 Expo config plugin,可自动应用上述所有 iOS 和 Android 原生配置。在 app.json 中:

{
"expo": {
"plugins": ["@qitech/react-native-device-scan"]
}
}

然后执行 prebuild 以应用原生改动:

npx expo prebuild