ios - 跟踪 iOS 应用程序的任何用户交互

标签 ios swift analytics interaction

如何跟踪或捕捉我的 iOS 应用的每次用户交互?就像按下 UIButton、UIBarButton ……任何 UIControl 元素一样。

我知道有数百种分析工具,如 Google Analytics、Flurry、Appsee 等,但我想将这些数据保存在我自己的服务器上。

最佳答案

您可以子类化 UIApplication:

  • 创建一个 UIApplication 子类
  • 覆盖 sendAction(_ action: Selector, to target: Any?, from sender: Any?, for event: UIEvent?) 事件方法,记得调用super实现
  • 在实现中放入 NSLog 或其他诊断代码

例如,这将在每次按下 UIButton 时打印一条日志:

func sendAction(_ action: Selector, to target: Any?, from sender: Any?, for event: UIEvent?) -> Bool {
    if (sender is UIButton) {
        print("Action: \(NSStringFromSelector(action)) - \(target) - \(sender)")
    }
    return super.sendAction(action, to: target, from: sender, for: event)
}


2017-07-08 14:46:18.270 UIApplicationSubclass[94764:c07] Action: anAction: - <ViewController: 0x76790a0> - <UIRoundedRectButton: 0x767b9b0; frame = (103 66; 73 44); opaque = NO; autoresize = TM+BM; layer = <CALayer: 0x767bad0>>
2017-07-08 14:46:27.378 UIApplicationSubclass[94764:c07] Action: anAction: - <ViewController: 0x76790a0> - <UIRoundedRectButton: 0x767b9b0; frame = (103 66; 73 44); opaque = NO; autoresize = TM+BM; layer = <CALayer: 0x767bad0>>

对于 objective-c 引用 click here

关于ios - 跟踪 iOS 应用程序的任何用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47413251/

相关文章:

ios - InApp 不适用于 iOS 5.1.1

azure - Azure 门户和 App Insights Analytics 中显示的不同用户数据

javascript - 自定义事件数据中未定义 WoopraTracker

php - 从脚本中获取访问者数量

swift - 如何使 ScrollView 内的 TableView 的滚动行为自然

swift - 测试时如何断言异步抛出错误?

ios - 如何在 SwiftUI 中为单行文本设置行高?

ios - curl -L 通过 Alamofire for Swift 3 从 Box 获取文件内容

ios - 使用 Swift 创建 Gameboy 游戏

objective-c - 如何将此 Swift 行转换为 Objective-C 语法