logging - Log every button press / interaction in an iOS App -
is there way catch sorts of user interactions, first , foremost button presses in ios app? i'm interested in logging these events time stamp , ideally name of screen appear on.
i guess simplest way insert call of custom log function every action called button. that's effort.
i thought subclassing uibutton
, still require me change every button in existing app , work buttons (not cells in table example).
is there point can intercept touches in general? or point know button pressed , i've reference button?
(we research usability testing of mobile apps, aim @ modular solution can reused , needs little manual changes of code possible. suggestions welcome, since realize might not easy.)
you can subclass uiapplication:
- create uiapplication subclass
- override
-(bool)sendaction:(sel)action to:(id)target from:(id)sender forevent:(uievent *)event
method, remember call super implementation - put
nslog
or other diagnostic code inside implementation
example, print log every time uibutton 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>>
moreover, subclass uiapplication, must change main.m file (in case uiapplication subclass named flapplication, @ third parameter of uiapplicationmain function , 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])); } }
Comments
Post a Comment