Search code examples
iosobjective-cjailbreaktheosspringboard

'SpringBoard' may not respond to presentViewController


I'm currently trying to make a very simple baseline tweak for iOS 9.3.3 to just display a message when Springboard starts. It keeps giving me this error and I can't figure out how to correct it. Any help would be greatly appreciated. The reason I'm not using UIAlertView is because it is deprecated.

Error:

> Making all for tweak UIAlertControllerTest
==> Preprocessing Tweak.xm
==> Compiling Tweak.xm (armv7)
Tweak.xm:9:8: error: 'SpringBoard' may not respond to
  'dismissViewControllerAnimated:completion:' [-Werror]
    [self dismissViewControllerAnimated:YES completion:nil];
     ~~~~ ^
Tweak.xm:12:8: error: 'SpringBoard' may not respond to
  'presentViewController:animated:completion:' [-Werror]
    [self presentViewController:alertController animated:YES complet...
     ~~~~ ^
2 errors generated.
make[3]: ***     [/home/theodd/Desktop/uialertcontrollertest/.theos/obj/debug/armv7/Tweak.xm.ae1dfb2c.o] Error 1
make[2]: ***     [/home/theodd/Desktop/uialertcontrollertest/.theos/obj/debug/armv7/UIAlertControllerTest.dylib] Error 2
make[1]: *** [internal-library-all_] Error 2
make: *** [UIAlertControllerTest.all.tweak.variables] Error 2

Tweak.xm:

#import <SpringBoard/SpringBoard.h>

%hook SpringBoard

-(void)applicationDidFinishLaunching:(id)application {
%orig;
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"TestTitle" message:@"TestMessage" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}]];

[self presentViewController:alertController animated:YES completion:nil];
}

%end

Solution

  • I got it working, you guys! If you're curious on what the working code and Makefile was:

    Tweak.xm

    #import <SpringBoard/SpringBoard.h>
    
    %hook SpringBoard
    
    -(void)applicationDidFinishLaunching:(id)application {
        %orig;
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"TestTitle" message:@"TestMessage" preferredStyle:UIAlertControllerStyleAlert];
        [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [self.keyWindow.rootViewController dismissViewControllerAnimated:YES completion:NULL];
    }]];
    
        [self.keyWindow.rootViewController presentViewController:alertController animated:YES completion:NULL];
    }
    
    %end
    

    Makefile

    GO_EASY_ON_ME=1
    export ARCHS = armv7 arm64
    export TARGET = iphone:clang:9.3:9.3
    
    include $(THEOS)/makefiles/common.mk
    
    TWEAK_NAME = UIAlertControllerTest
    UIAlertControllerTest_FRAMEWORKS = UIKit
    UIAlertControllerTest_FILES = Tweak.xm
    
    include $(THEOS_MAKE_PATH)/tweak.mk
    
    after-install::
        install.exec "killall -9 SpringBoard"