Last active
October 28, 2015 01:09
-
-
Save tommeier/ff0fc26642c17e26604a to your computer and use it in GitHub Desktop.
Calabash Backdoor Workaround for missing shake gesture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
#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 | |
//... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Trigger the backdoor for shaking device | |
backdoor("calabashBackdoor:", "shake") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tommeier What would be
import "AppDelegate+Calabash.h" ?