'跳板'可能无法响应presentViewController

时间:2016-09-22 17:47:35

标签: ios objective-c jailbreak theos springboard

我目前正试图对iOS 9.3.3做一个非常简单的基线调整,以便在Springboard启动时显示一条消息。它一直给我这个错误,我无法弄清楚如何纠正它。任何帮助将不胜感激。我之所以不使用UIAlertView是因为它已被弃用。

错误

> 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

3 个答案:

答案 0 :(得分:1)

SpringBoardFBSystemApp,扩展名为UIApplication子类,而不是UIViewController。方法-presentViewController:animated:completion:UIViewController实例方法,因此您想从一个方法中调用它。

我建议你阅读有关课程如何工作的内容,基本的Objective-C内容,不必特定于越狱。

答案 1 :(得分:0)

或者只是使用UIAlertView,直到它们被弃用。例如

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

答案 2 :(得分:0)

我得到了它,你们!如果您对工作代码和Makefile是什么感到好奇:

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

生成文件

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"