陷阱 1.1.5

陷阱 1.1.5

Denes SapiBence GoldaMark Tolmacs 维护。



陷阱 1.1.5

  • Cursor Insight Ltd

适用于iOS和iPadOS的Trap库

该库可以收集各种设备和用户数据,并将其转发到指定的端点。以下数据收集器包含在本版本中:

  • 加速度计
  • 连接或对等连接的蓝牙LE设备
  • 近似和精确位置
  • 重力
  • 陀螺仪
  • 间接指针(鼠标)
  • 磁力计
  • 铅笔和触控笔
  • 捏合手势
  • 原始触摸
  • 滑动手势
  • 点击手势
  • WiFi连接和可用的网络

如何使用它

您可以查看示例应用程序以获取实际示例

import Trap
import SwiftUI

@main
struct ExampleApp: App {
    let trapManager: TrapManager

    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }

    public init() {
        /// Create a new configuration instance.
        var config = TrapConfig()
        
        /// Change what you need to change
        config.reporter.interval = .seconds(3)
        
        /// Set either a websocket endpoint...
        let ws_url = URL(string: "wss://example.com/api/ws")!
        
        /// ...or a HTTP POST endpont.
        let post_url = URL(string: "https://example.com/api/post")!
        
        trapManager = try! TrapManager(post_url, withConfig: config)

        // Run all default collectors...
        trapManager.runAll()
        
        // ...or use it one collector at a time
        let collector = TrapPreciseLocationCollector(withConfig: config)
        
        /// Check if the build-time conditions are ready for the collector
        if collector.checkConfiguration() {
            /// Check if the runtime permissions are given.
            if !collector.checkPermission() {
                /// Request the permission if you need to
                collector.requestPermission { [self] in trapManager.run(collector: collector) }
            } else {
                /// ...or run the collector immediately.
                trapManager.run(collector: collector)
            }
        }
    }
}

权限

许多可用的数据收集器需要应用包记录(Info.plist)和/或授权项目。其中一些需要Apple的特殊批准。以下是每个收集器的详细信息:

加速度计、重力、陀螺仪、磁力计

唯一要求是确保包记录 'NSMotionUsageDescription' 定义并填写。

蓝牙LE

唯一要求是确保包记录 'NSBluetoothAlwaysUsageDescription' 定义并填写。需要用户在运行时授予权限。

近似位置和精确位置

需要设置以下包记录

  • NSLocationAlwaysAndWhenInUseUsageDescription
  • NSLocationWhenInUseUsageDescription
  • NSLocationWhenInUseUsageDescription
  • NSLocationUsageDescription

需要用户在运行时授权。

WiFi

以下权限用于完全操作

  • com.apple.developer.networking.HotspotHelper
  • com.apple.developer.networking.wifi-info

只有在Apple批准您的应用程序后才能获得HotspotHelper权限(可在Apple HotspotHelper 请求中找到)。

开发说明

库的核心是TrapManager类,它管理单个收集器,这些收集器可供最终开发者使用。另一个方面是数据帧传输系统,这是一个可配置间隔的无尽重复任务。报告任务将数据包发送到指定的终点。这两个方面的连接是一个内存数据存储,通过自定义环形队列实现。

实施的目标是低且可预测的资源使用。因此,我们在关键UI路径上尽最大可能避免分配和处理。处理部分主要由后台线程完成。为此,我们使用操作队列。

法律警告

该库收集的许多数据类型可以识别个别用户,因此集成应用可能受到GDPR和/或CCPA的影响。您对本库收集和处理的数据负全责。

授权许可

根据MIT授权许可的。