I've created a simple tweak, using Theos, that adds an yellow UIView to the app window (nothing special), and it works perfectly. Then I made a dylib file (called AlertLib), containing one class (called AlertLib as well), with one method: to show a simple UIAlertView
. I copied the AlertLib.dylib to /opt/theos/lib folder, and AlertLib.h to /opt/theos/include folder.
My Makefile looks this way:
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"
And Tweak.xm file looks this way:
#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
After that I compiled the tweak, and installed it to device, with no error. But, now tweak isn't working, i.e no yellow view is added on app's window, and no alert is shown. How correctly to embed a custom dylib file to tweak?
I solved my issue by adding my custom library as a subproject to my tweak.
I run the command /opt/theos/bin/nic.pl
in my tweak's root directory, and chose library from the list. It was added automatically as a subproject. Then I added needed files to my library, and it worked.