2

I want to be able to track what buttons my users are tapping. Is there a way to "capture" or "log" all the button taps inside my app?

I was thinking about method swizzling but I really rather not get into that.

YogevSitton
  • 10,068
  • 11
  • 62
  • 95

3 Answers3

1

Aspect Programming may help you. Have a look at this library :

https://github.com/steipete/Aspects

Basically you do something like :

[UIButton aspect_hookSelector:@selector(whateverSelectorYouWantToHookOn:) 
                  withOptions:AspectPositionAfter 
                   usingBlock:^(id<AspectInfo> aspectInfo) {
   NSLog(@"UIButton called");
} 
error:NULL];

Have a look on the AspectInfo for more information on the instance called.

vivien.destpern
  • 1,020
  • 1
  • 7
  • 14
0

Buttons can have multiple actions attached to them. You could always add a logging action to each of your buttons. The action method receives the sender, so you could log information about the button that was tapped.

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • I want to do something more "general" that will affect all the buttons in my app without having to add code to each of them. – YogevSitton Dec 17 '14 at 15:45
0

You can subclass UIButton to add logging. The accepted answer on

objective C: Buttons created from subclass of UIButton class not working

has a good explanation on why this is one of the few instances that subclassing may be useful.

Basically UIButton inherits from UIControl and UIControl Class Reference states

Subclassing Notes You may want to extend a UIControl subclass for either of two reasons:

To observe or modify the dispatch of action messages to targets for particular events
To provide custom tracking behavior (for example, to change the highlight appearance)

Community
  • 1
  • 1
Jon
  • 71
  • 1
  • 2