@ expop/ react- native- efp- 人群连接
用于CrowdConnected定位跟踪和室内定位服务的回放原生涡轮模块. 提供跨平台访问GPS,IPS(室内定位系统),并基于蓝牙在iOS和Android上的定位.
特征
- 📍 多位置支持:全球定位系统、室内定位和蓝牙
- 📱 跨平台: 原生iOS(Swift)和Android(Kotlin)实施
- ⚡ 反应原生新建筑: 建为最佳性能的涡轮模块
- 🔔 基于事件: 通过事件听众实时更新位置
- 🔄 背景支持: 可选背景位置更新
- 🎯 标题跟踪: 编译/载有信息
- 📦 先输入脚本: 带有生成类型定义的完整类型安全
所需资源
- Android 7.0+ (API 级别 24+)
- iOS 16.0+ (被捆绑的"人群"所需要) SDK
安装
npm install @expofp/react-native-efp-crowdconnected
# or
yarn add @expofp/react-native-efp-crowdconnected
iOS系统
cd ios && pod install
你的软件主机 Info.plist 必须声明相关位置/蓝牙使用说明 UIBackgroundModes 条目。 见 example/ios/ExpofpCrowdconnectedExample/Info.plist 用于工作配置.
机器人
Gradle 自动解决依赖关系. 拥挤的SDK AARs(net.crowdconnected.android.{core,background,geo,ips},从CrowdConnect's Maven寄存器中取出)通过Gradle的表单并购提供前景服务声明和以下权限. 您不需要在您的主机应用程序中声明 AndroidManifest.xml数字 : INTERNET, (中文(简体) ), ACCESS_FINE_LOCATION, (中文(简体) ), ACCESS_COARSE_LOCATION, (中文(简体) ), FOREGROUND_SERVICE, (中文(简体) ), FOREGROUND_SERVICE_LOCATION, (中文(简体) ), BLUETOOTH_SCAN, (中文(简体) ), BLUETOOTH_CONNECT和遗产 BLUETOOTH 编号 : BLUETOOTH_ADMIN (单位:千美元)maxSdkVersion=30) (中文(简体) ).
如果你准备好了 isBackgroundUpdateEnabled: true,您的主机应用程序 必须 并宣布:
<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
ACCESS_BACKGROUND_LOCATION 无法从Android 11+上的标准运行时间提示给予;系统将用户重定向到应用程序的设置屏幕上,在屏幕上必须选择"Allow all the time".
快速启动
import { CrowdConnectedLocationProvider } from '@expofp/react-native-efp-crowdconnected';
// Initialize
await CrowdConnectedLocationProvider.setup({
appKey: 'your-app-key',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
navigationType: 'all', // 'all' | 'GEO' | 'IPS'
isBackgroundUpdateEnabled: false,
isBluetoothEnabled: true,
isHeadingEnabled: true,
});
// Listen to location updates
const unsubscribe = CrowdConnectedLocationProvider.onLocationChange((position) => {
console.log('Location:', position);
// { lat: number, lng: number, x?: number, y?: number, z?: string | number, angle?: number }
});
// Listen to errors
const unsubscribeError = CrowdConnectedLocationProvider.onError((error) => {
console.error('Location error:', error);
});
// Start tracking
CrowdConnectedLocationProvider.startUpdatingLocation();
// Check if location tracking is active
const isUpdating = await CrowdConnectedLocationProvider.isLocationUpdating();
// Stop tracking
CrowdConnectedLocationProvider.stopUpdatingLocation();
// Cleanup
unsubscribe();
unsubscribeError();
API 参考
setup(settings: ExpoFpLocationSettings): Promise<ExpoFpProviderInfo>
以配置初始化 CrowdConnected SDK.
参数:
appKey- 人群连接应用程序密钥clientId- 人群连接客户端IDclientSecret- 拥挤的客户秘密navigationType- 定位类型:'all'(GPS + IPS ),'GEO'(仅限一般服务费用),'IPS'(仅室内)isBackgroundUpdateEnabled- 启用背景位置更新isBluetoothEnabled- 启用以蓝牙为基础的定位isHeadingEnabled- 启用指南针/标题跟踪aliases?- 自定义位置别名(可选)
回返情况: 承诺决心 ExpoFpProviderInfo (单位:千美元){ deviceId?, isLocationUpdating }(中文(简体) )
startUpdatingLocation(): Promise<ExpoFpProviderInfo>
开始追踪位置.
stopUpdatingLocation(): Promise<ExpoFpProviderInfo>
停止追踪位置.
isLocationUpdating(): Promise<ExpoFpProviderInfo>
返回当前提供者状态.
onLocationChange(callback: (position: ExpoFpPosition) => void): Unsubscribe
订阅位置更新 .
位置对象 :
{
lat?: number; // Latitude
lng?: number; // Longitude
x?: number; // X coordinate (indoor)
y?: number; // Y coordinate (indoor)
z?: string|number; // Z coordinate (floor/level)
angle?: number; // Heading in degrees
}
回返情况: 取消订阅函数
onError(callback: (error: Error) => void): Unsubscribe
订阅位置错误 .
回返情况: 取消订阅函数
模拟模式
模拟模式在设备上重放GPS/IPS路径而不进行物理运动. 模拟职位通过经常预算抵达 onLocationChange 听着.
const simulationToken = '<signed JWT for the simulation session>';
// The SDK must already be started (startUpdatingLocation) before activating.
const unsubConnected = CrowdConnectedLocationProvider.onSimulationConnected(() => {
console.log('Simulation connected');
});
const unsubDisconnected = CrowdConnectedLocationProvider.onSimulationDisconnected(() => {
console.log('Simulation disconnected');
});
const unsubError = CrowdConnectedLocationProvider.onSimulationError((error) => {
console.error('Simulation error:', error.message);
});
CrowdConnectedLocationProvider.activateSimulation(simulationToken);
// ...later
CrowdConnectedLocationProvider.deactivateSimulation();
// Cleanup
unsubConnected();
unsubDisconnected();
unsubError();
activateSimulation(token: string): void
开始模拟会话 。 火灾和遗忘:结果通过 onSimulationConnected 编号 : onSimulationError 事件.
token- 为模拟会议签发的署名JWT(包括:sid会话标识和exp索赔)- SDK必须已经通过
startUpdatingLocation() - 再次调用它取代了本届会议
- 调用前取消模拟
stopUpdatingLocation()当会话活动时
deactivateSimulation(): void
停止活动模拟会话。 无会话活动时安全禁用 .
onSimulationConnected(callback: () => void): Unsubscribe
模拟会话建立时起火.
onSimulationDisconnected(callback: () => void): Unsubscribe
模拟会话结束后会起火.
onSimulationError(callback: (error: Error) => void): Unsubscribe
模拟会话失败时起火( 如无效或过期的令牌) .
发展
设置
yarn install
yarn prepare
图标
yarn lint- 运行ESLintyarn typecheck- 检查类型脚本yarn test- 运行杰斯特测试yarn example ios- 运行iOS实例应用程序yarn example android- 运行Android实例应用程序yarn clean- 清洁建筑文物