ci-trap-ios
所属分类:iPhone/iOS
开发工具:Swift
文件大小:0KB
下载次数:0
上传日期:2023-10-20 19:26:02
上 传 者:
sh-1993
说明: 用于Cursor Insight trap服务器的触摸和传感器数据采集器iOS和iPadOS库。,
(Touch and sensor data collector iOS and iPadOS library for the Cursor Insight trap server.,)
文件列表:
.swiftpm/ (0, 2023-12-19)
.swiftpm/xcode/ (0, 2023-12-19)
.swiftpm/xcode/Trap.xctestplan (377, 2023-12-19)
.swiftpm/xcode/package.xcworkspace/ (0, 2023-12-19)
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata (135, 2023-12-19)
.swiftpm/xcode/xcshareddata/ (0, 2023-12-19)
.swiftpm/xcode/xcshareddata/xcschemes/ (0, 2023-12-19)
.swiftpm/xcode/xcshareddata/xcschemes/Trap.xcscheme (2851, 2023-12-19)
Example/ (0, 2023-12-19)
Example/Example-Info.plist (362, 2023-12-19)
Example/Example.entitlements (393, 2023-12-19)
Example/Example.xcodeproj/ (0, 2023-12-19)
Example/Example.xcodeproj/project.pbxproj (16009, 2023-12-19)
Example/Example.xcodeproj/xcshareddata/ (0, 2023-12-19)
Example/Example.xcodeproj/xcshareddata/xcschemes/ (0, 2023-12-19)
Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme (2923, 2023-12-19)
Example/Example.xcworkspace/ (0, 2023-12-19)
Example/Example.xcworkspace/contents.xcworkspacedata (239, 2023-12-19)
Example/Example.xcworkspace/xcshareddata/ (0, 2023-12-19)
Example/Example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist (238, 2023-12-19)
Example/Example.xcworkspace/xcshareddata/swiftpm/ (0, 2023-12-19)
Example/Example.xcworkspace/xcshareddata/swiftpm/Package.resolved (606, 2023-12-19)
Example/Sources/ (0, 2023-12-19)
Example/Sources/Assets.xcassets/ (0, 2023-12-19)
Example/Sources/Assets.xcassets/AccentColor.colorset/ (0, 2023-12-19)
Example/Sources/Assets.xcassets/AccentColor.colorset/Contents.json (123, 2023-12-19)
Example/Sources/Assets.xcassets/AppIcon.appiconset/ (0, 2023-12-19)
Example/Sources/Assets.xcassets/AppIcon.appiconset/Contents.json (177, 2023-12-19)
Example/Sources/Assets.xcassets/Contents.json (63, 2023-12-19)
Example/Sources/ContentView.swift (467, 2023-12-19)
Example/Sources/ExampleApp.swift (1311, 2023-12-19)
Example/Sources/Preview Content/ (0, 2023-12-19)
Example/Sources/Preview Content/Preview Assets.xcassets/ (0, 2023-12-19)
Example/Sources/Preview Content/Preview Assets.xcassets/Contents.json (63, 2023-12-19)
... ...
# Trap Library for iOS and iPadOS
This library can collect various device and user data, forwarding it to a specified endpoint. The following data collectors are bundled with this version:
* Accelerometer
* Battery status
* Bluetooth LE devices connected / peered
* Approximate and precise location
* Gravity
* Gyroscope
* Indirect pointer (mouse)
* Magnetometer
* Pencil and stylus
* Pinch gesture
* Raw touch
* Swipe gesture
* Tap gesture
* WiFi connection and available networks
## How to use it
You can check out the Example app for a working example
```swift
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...
config.reporter.url = "wss://example.com/api/ws"
/// ...or a HTTP POST endpont.
config.reporter.url = "https://example.com/api/post"
trapManager = TrapManager(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)
}
}
}
}
```
## Providing custom metadata
You can add and remove custom metadata (a string key-value pair), that will be
sent to the server periodically as part of the metadata event.
Adding metadata:
```
trapManager.addCustomMetadata(key: "some-key", value: "some-value")
```
Removing metadata:
```
trapManager.removeCustomMetadata(key: "some-key")
```
## Sending event with custom data
You can add a custom event to the event stream as well. This can contain simple
types (string, numeric, boolean) and complex types (dictionaries and arrays of
these types) as well.
```
trapManager.addCustomEvent(custom: DataType.dict([
"some-key": DataType.string("some-data"),
"numeric-data-key": DataType.int(2),
"boolean-data-key": DataType.bool(false)
]))
```
## Permissions
Many of the available data collectors require app bundle records (Info.plist) and/or entitlemens. Some of them needs Apple's special approval. Below are the details for each collector:
### Accelerometer, Gravity, Gyroscope, Magnetometer
The only requirement is to have the bundle record 'NSMotionUsageDescription' defined and filled in.
### Bluetooth LE
The only requirement is to have the bundle record 'NSBluetoothAlwaysUsageDescription' defined and filled in. Requires runtime permission from the user.
### Approximate and precise location
The following bundle records need to be set:
* NSLocationAlwaysAndWhenInUseUsageDescription
* NSLocationWhenInUseUsageDescription
* NSLocationWhenInUseUsageDescription
* NSLocationUsageDescription
Requires runtime permission from the user.
### WiFi
The following entitlements needed for full operation:
* com.apple.developer.networking.HotspotHelper
* com.apple.developer.networking.wifi-info
The HotspotHelper entitlement can only be acquired if Apple approves your application (available at [Apple HotspotHelper Request](https://developer.apple.com/contact/request/hotspot-helper/)).
## Development notes
The core of the library is the TrapManager class. It manages the individual colllectors, which are available to the end developer. The other aspect is the data frame transport system, which is an endlessly repeating task with a configurable interval. The reporting task sends the data packets to the specified endpoint. The connection between the two aspects is a memory data store, which is implemented via a custom ring queue.
The goal of the implementation is low and predictably flat resource usage. Therefore on the critical UI path we attempted to avoid allocation and processing as much as possible. The processing part is mostly happening on a background thread. For this we use OperationQueues.
## Legal Warning
Many of the data types collected by this library is capable of identifying the individual user, therefore the integrating app can be affected by GDPR and/or CCPA. You are solely responsible for the data collected and processed via this library.
## License
Licensed under the MIT license.
近期下载者:
相关文件:
收藏者: