要使用 CocoaPods 将 pinpoint-easylocate-ios
Pod 集成到您的 Xcode 项目中,请在您的 Podfile
中指定它
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'
target 'YourAppTargetName' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for YourAppTargetName
pod 'pinpoint-easylocate-ios', '~> 11.4.1.5'
end
然后在您的终端中运行以下命令
pod install
要使用 pinpoint-easylocate-ios
Pod 在您的 iOS 项目中使用,请按照以下步骤集成并使用由 Pod 提供的 API 类。
首先,在您的 Swift 文件顶部导入模块
import pinpoint_easylocate_ios
API
类提供了各种函数,用于通过蓝牙与附近的追踪器交互。以下是可供公开使用的的主要函数
访问 API
类的单例实例
let api = API.shared
开始扫描具有指定超时的附近追踪器。完成处理程序返回发现的追踪器列表。
api.scan(timeout: 10.0) { tracelets in
print("Discovered tracelets: \(tracelets)")
}
停止扫描过程
api.stopScan()
异步连接到发现的追踪器。该函数返回一个 Bool
指示是否成功。
let discoveredTracelets = [...] // This is obtained from the scan() completion handler
if let tracelet = discoveredTracelets.first {
do {
let success = try await api.connect(device: tracelet)
print("Connection success: \(success)")
} catch {
print("Connection failed with error: \(error)")
}
}
连接到追踪器并开始定位
if let tracelet = discoveredTracelets.first {
do {
let success = try await api.connectAndStartPositioning(device: tracelet)
print("Connection and positioning success: \(success)")
} catch {
print("Connection and positioning failed with error: \(error)")
}
}
从追踪器断开连接
api.disconnect()
let xPos = api.localPosition.xCoord
let yPos = api.localPosition.yCoord
SwiftUI 示例
.onAppear {
// Set initial position
xPos = api.localPosition.xCoord
yPos = api.localPosition.yCoord
}
.onChange(of: api.localPosition) { newPosition in
// Update position when localPosition changes
xPos = newPosition.xCoord
yPos = newPosition.yCoord
}
向连接的追踪器发送 "ShowMe" 命令
api.showMe()
在连接的追踪器上启动 UWB 定位
api.startPositioning()
在连接的追踪器上停止 UWB 定位
api.stopPositioning()
设置通信通道(5 或 9)
let success = api.setChannel(channel: 5)
print("Channel set success: \(success)")
为追踪器设置 SiteID
let success = await api.setSiteID(siteID: 0x0001)
print("SiteID set success: \(success)")
设置定位间隔
api.setPositioningInterval(interval: 1) // Interval in n x 250ms, Default: 1 (update every 1 x 259ms)
请求连接的追踪器的状态
if let status = await api.getStatus() {
print("Tracelet status: \(status)")
}
请求连接的追踪器的固件版本
if let version = await api.getVersion() {
print("Tracelet firmware version: \(version)")
}
如果您遇到 rsync 缺少权限的错误,请确保将您的 Xcode 项目构建选项 ENABLE_USER_SCRIPT_SANDBOXING 更新为 'No'。