Skip to content

Instantly share code, notes, and snippets.

@ArtikusHG
Created August 24, 2017 13:32
Show Gist options
  • Save ArtikusHG/aad1372639d90674bdefc5ac50915d62 to your computer and use it in GitHub Desktop.
Save ArtikusHG/aad1372639d90674bdefc5ac50915d62 to your computer and use it in GitHub Desktop.
Adding a sharedInstance to the SpringBoard so you can call methods from it (with an example of calling a method).
// Needed interface which includes the sharedInstance, and a void for the example
@interface SpringBoard
+ (id)sharedInstance;
- (void)_simulateHomeButtonPress;
@end
%hook SpringBoard
// We create the sharedInstance. It's empty for now, so we ake it useful in the next methods
// P.S. I wanted to make a __weak, but it didn't compile, and a __strong magically worked
static SpringBoard *__strong sharedInstance;
// Just make the sharedInstance the same thing as init
- (id)init {
id original = %orig;
sharedInstance = original;
return original;
}
// Finally, we create a %new + (id), and make it return itself (sharedInstance) so it's accessable from anywhere else in the class
%new
+ (id)sharedInstance {
return sharedInstance;
}
%end
// Now, the example
// it 'presses' the home button when an application is launched
%hook SBApplication
- (void)didAnimateActivation {
[[objc_getClass("SpringBoard") sharedInstance] _simulateHomeButtonPress];
}
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment