簡単なTweak作成方法
どうもmikiyan1978です。
今回は初心者向けの簡単なTweakを作っていきましょう。
Respringから復帰したその5秒後にRespringするかどうかを示すアラートを表示させるTweakです。
よく脱獄系のブログで見られる%hookを使った方法では無く独自のやり方で作成します。
theos構築などは割愛します。
早速Tweakプロジェクトを作成します。名前は
springalert
としましょう。
そしてTweak.xmに
#import <objc/runtime.h> @interface FBSystemService : NSObject + (id)sharedInstance; - (void)exitAndRelaunch:(BOOL)arg1; @end %ctor { %init; [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidFinishLaunchingNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Respringアラート" message:@"Respringしますか?" preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [[objc_getClass("FBSystemService") sharedInstance] exitAndRelaunch:YES]; }]]; [alert addAction:[UIAlertAction actionWithTitle:@"いいえ" style:UIAlertActionStyleCancel handler:nil]]; [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:alert animated:YES completion:nil]; }); }]; }
このように書きます。難しい事は抜きにしましょう。
次にMakefileには
ARCHS = arm64 arm64e
#下記は使用するSDKと最低動作iOSバージョンです
#必要に応じて書き換え/コメントアウト解除してください。
#TARGET = iphone:clang:latest:10.0
INSTALL_TARGET_PROCESSES = SpringBoard
include $(THEOS)/makefiles/common.mk
TWEAK_NAME = springalert
$(TWEAK_NAME)_FILES = $(wildcard *.xm)
$(TWEAK_NAME)_FRAMEWORKS = UIKit
include $(THEOS_MAKE_PATH)/tweak.mk
編集は以上です。あとはmake packageしてください。