记录iOS应用程序中的每个按钮按下/交互 [英] Log every button press / interaction in an iOS App

查看:71
本文介绍了记录iOS应用程序中的每个按钮按下/交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法捕捉各种用户互动,但首先在iOS应用中按下按钮?我有兴趣用时间戳记录这些事件,理想情况下是它们出现的屏幕名称。

Is there a way to catch all sorts of user interactions, but first and foremost button presses in an iOS app? I'm interested in logging these events with a time stamp and ideally with the name of the screen they appear on.

我想最简单的方法是插入一个自定义日志功能到按钮调用的每个操作中。但这太费劲了。

I guess the simplest way is to insert a call of a custom log function into every action called by a button. But that's too much effort.

我还考虑过继承 UIButton ,但这仍然需要我改变每一个现有应用程序中的按钮,仅适用于按钮(例如,不适用于表格中的单元格)。

I also thought about subclassing UIButton, but this would still require me to change every button in an existing app and would work only for buttons (not cells in a table for example).

我是否可以拦截一般的触摸?或者有一点我特别知道按下了一个按钮并且我引用了那个按钮?

Is there a point were I can intercept touches in general? Or a point were I specifically know a button was pressed and I've a reference to that button?

(我们研究移动应用程序的可用性测试,所以我们的目标是模块化解决方案,可以很容易地重复使用,并且需要尽可能少地手动更改代码。但欢迎任何建议,因为我意识到这可能不那么容易。)

(We research usability testing of mobile apps, so we aim at a modular solution that can be easily reused and needs as little manual changes of code as possible. But any suggestions are welcome, since I realize this might not be so easy.)

推荐答案

您可以继承UIApplication:

You can subclass UIApplication:


  • 创建UIApplication子类

  • 覆盖 - (BOOL)sendAction:(SEL)动作:((id)目标来自:(id)sender forEvent:(UIEvent *)event 方法,记得要调用超级实现

  • 在实现中放入 NSLog 或其他诊断代码

  • Create an UIApplication Subclass
  • override the -(BOOL)sendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event method, remember to call the super implementation
  • put an NSLog or other diagnostic code inside the implementation

例如,每次按下UIButton时都会打印一个日志:

Example, this will print a log every time an UIButton is pressed:

-(BOOL)sendAction:(SEL)action to:(id)target from:(id)sender forEvent:(UIEvent *)event
{
    if ([sender isKindOfClass:[UIButton class]])
    {
        NSLog(@"Action: %@ - %@ - %@", NSStringFromSelector(action), target, sender);
    }

    return [super sendAction:action to:target from:sender forEvent:event];
}


2013-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>>
2013-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>>

此外,要继承UIApplication,你必须像这样更改main.m文件(在我的情况下, UIApplication子类名为FLApplication,查看UIApplicationMain函数的第三个参数和FLApplication.h的导入。

Moreover, to subclass UIApplication, you must change the main.m file like this (In my case the UIApplication subclass was named FLApplication, look at the third parameter of the UIApplicationMain function and the import of FLApplication.h)

#import "AppDelegate.h"
#import "FLApplication.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, NSStringFromClass([FLApplication class]), NSStringFromClass([AppDelegate class]));
    }
}

这篇关于记录iOS应用程序中的每个按钮按下/交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆