Skip to content

Instantly share code, notes, and snippets.

@tommeier
Last active October 28, 2015 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommeier/ff0fc26642c17e26604a to your computer and use it in GitHub Desktop.
Save tommeier/ff0fc26642c17e26604a to your computer and use it in GitHub Desktop.
Calabash Backdoor Workaround for missing shake gesture
//
// AppDelegate+Calabash.m
//
// Only loaded for calabash target (where preprocesser has CALABASH=1)
#import "AppDelegate+Calabash.h"
@implementation AppDelegate (Calabash)
- (NSString *)calabashBackdoor:(NSString *)command {
if ([command isEqualToString:@"shake"]) {
UIEvent *m = [[UIEvent alloc] init];
[[UIApplication sharedApplication] sendEvent:m];
[[[UIApplication sharedApplication] keyWindow] motionBegan:UIEventSubtypeMotionShake withEvent:m];
[[[UIApplication sharedApplication] keyWindow] motionEnded:UIEventSubtypeMotionShake withEvent:m];
} else {
SEL selector = NSSelectorFromString(command);
if ([self respondsToSelector:selector]) {
DDLogInfo(@"Sending backdoor calabash command: %@", command);
[self performSelector:@selector(selector) withObject:nil];
} else {
DDLogWarn(@"Unrecognised backdoor calabash command: '%@'. Skipping.", command);
}
}
return command;
}
@end
//...
#import "AppDelegate.h"
#if CALABASH
// Calabash target has a preprocessor set for 'CALABASH=1' in both debug + release
#import "AppDelegate+Calabash.h" // Calabash helpers
#endif
//...
# Trigger the backdoor for shaking device
backdoor("calabashBackdoor:", "shake")
@mansis15
Copy link

@tommeier What would be

import "AppDelegate+Calabash.h" ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment