How can I track or catch every user interaction of my iOS app? Like pressing an UIButton, UIBarButton, ... any UIControl element.
I know there are hundreds of analytics tools like Google Analytics, Flurry, Appsee and so on, but I want to save these data on my own server.
You can subclass UIApplication:
Example, this will print a log every time an UIButton is pressed:
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>>
For objective-c reference click here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With