0

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
TheOdd
  • 265
  • 1
  • 16

3 Answers3

1

SpringBoard is a FBSystemApp, and by extension, UIApplication subclass, not UIViewController. The method -presentViewController:animated:completion: is a UIViewController instance method, so you want to call it from one.

I suggest you do some reading up on how classes work, the basic Objective-C stuff, doesn't have to be jailbreak-specific.

0

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"
TheOdd
  • 265
  • 1
  • 16
-1

Or just use an UIAlertView until they're deprecated. Eg.

UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"This is a title" message:@"This is a message" delegate:nil cancelButtonTitle:@"Ok!" otherButtonTitles:nil]; [a show]; [a release];