【发布时间】:2017-07-24 08:51:04
【问题描述】:
我创建了一个简单的调整,使用Theos,将黄色的 UIView 添加到应用程序窗口(没什么特别的),并且效果很好。然后我用一种方法制作了一个 dylib 文件(称为 AlertLib),其中包含一个类(也称为 AlertLib):显示一个简单的UIAlertView。我将 AlertLib.dylib 复制到 /opt/theos/lib 文件夹,并将 AlertLib.h 复制到 /opt/theos/include 文件夹。
我的 Makefile 看起来是这样的:
export ARCHS = armv7 arm64
export TARGET = iphone:clang:latest:8.0
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = YellowSquare
YellowSquare_FILES = Tweak.xm
YellowSquare_FRAMEWORKS = UIKit Foundation
YellowSquare_LDFLAGS = -lAlertLib
include $(THEOS_MAKE_PATH)/tweak.mk
after-install::
install.exec "killall -9 SpringBoard"
Tweak.xm 文件看起来是这样的:
#import "AlertLib.h"
%hook AppDelegate
- (void) applicationDidBecomeActive:(UIApplication *) application
{
static dispatch_once_t once;
dispatch_once(&once, ^{
UIView *yellowSquareView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
yellowSquareView.backgroundColor = [UIColor yellowColor];
UILabel *tweakLabel = [[UILabel alloc] initWithFrame:yellowSquareView.bounds];
tweakLabel.backgroundColor = [UIColor clearColor];
tweakLabel.text = @"TWEAK";
tweakLabel.font = [UIFont systemFontOfSize:25];
tweakLabel.textAlignment = NSTextAlignmentCenter;
[yellowSquareView addSubview:tweakLabel];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
yellowSquareView.center = window.center;
[window addSubview:yellowSquareView];
[[AlertLib sharedInstance] showAlert];
});
%orig;
}
%end
之后,我编译了调整,并将其安装到设备上,没有错误。但是,现在调整不起作用,即在应用程序的窗口上没有添加黄色视图,也没有显示警报。如何正确嵌入自定义 dylib 文件进行调整?
【问题讨论】: