久しぶりの更新です。
theos環境を整えてみたくて色々試した結果
成功した方法をメモがてら投稿したいと思います。
theosとは…Linux/Mac OSX/iOS/Windows(非公式)でiOS用Tweaksの開発を支援するためのツール
今回は以下の環境で行いました
PC:MacBook Pro (Retina, 13-inch, Early 2013)
OS:OS X Yosemite 10.10.5
Xcode 7.2.1(7C1002)
■事前準備
theosをインストールする前に以下のツールもしくはパッケージをインストールしてください
・Xcode
・CommandLineTool
・MacPorts
MacPortsを使用し以下のパッケージをインストール
・wget
・dpkg
・ldid
・openssl(人によっては不要)
■theos Install
~/ .bash_profileファイルに以下のコードを追記
export THEOS=/opt/theos export PATH=$THEOS/bin:$PATH
.bash_profileファイルを保存後【ターミナル】を再起動してください
以下のコマンドを実行しtheosをインストール
sudo git clone --recursive https://github.com/theos/theos.git $THEOS
これだけです
■実際にTweaksを作ってみる
【ターミナル】を開き以下のコマンドを実行
$THEOS/bin/nic.pl
NIC 2.0 - New Instance Creator ------------------------------ [1.] iphone/activator_event [2.] iphone/application_modern [3.] iphone/cydget [4.] iphone/flipswitch_switch [5.] iphone/framework [6.] iphone/ios7_notification_center_widget [7.] iphone/library [8.] iphone/notification_center_widget [9.] iphone/preference_bundle_modern [10.] iphone/tool [11.] iphone/tweak [12.] iphone/xpc_service Choose a Template (required):
今回はtweakを作成するので[11]とタイプしEnter
Project Name (required): Test Package Name [com.yourcompany.test]: com.NEXTi4HACK.Test Author/Maintainer Name [NEXTi4HACK]:
こんな感じで作成しました。
プロジェクト名はTest
パッケージ名はcom.NEXTi4HACK.Test
作成者はパッケージ名が設定されていれば自動で入るのでEnter
あとは全部Enter
カレントディレクトリにプロジェクト名のフォルダが作成されます
中身はこんなんです
theos:theosへのシンボリックリンク
control:debパッケージ構築の際に使用するファイル
Makefile:パッケージをビルドするとき使用するファイル
Tweak.xm:プログラムファイル(これがメイン)
Test.plist:Tweakの対象を記したファイル
ここら辺からは疎かったのでichitasoさんの記事を参考にさせていただきました。
Tweak.xmのソースコードはこんな感じです
#import <SpringBoard/SpringBoard.h> %hook SpringBoard -(void)applicationDidFinishLaunching:(id)application { %orig; UIViewController *view = [UIApplication sharedApplication].keyWindow.rootViewController; while (view.presentedViewController != nil && !view.presentedViewController.isBeingDismissed) { view = view.presentedViewController; } UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"テスト" message:@"単なるテストなんですよ" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"はい" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { //ボタンが押された時の処理 }]]; [alertController addAction:[UIAlertAction actionWithTitle:@"いいえ" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { //ボタンが押された時の処理 }]]; [view presentViewController:alertController animated:YES completion:nil]; } %end
(Objective-cでアプリ開発を行っていた人などはAppDelegateでこんなソースをよく見たことあるのでは?)
ichitasoさんのソースと違うところはUIAlertViewはiOS8以降で廃止になっているのでiOS8/9以降に対応させるためにUIAlertControllerに変えたくらいですかね(あとrootViewの取得)
続いてMakefile
ARCHS = armv7 arm64 include $(THEOS)/makefiles/common.mk TWEAK_NAME = Test Test_FILES = Tweak.xm Test_FRAMEWORKS = UIKit include $(THEOS_MAKE_PATH)/tweak.mk after-install:: install.exec "killall -9 SpringBoard"
一番上に[ARCHS = armv7 arm64]と
プロジェクト名_FILESの下に
[プロジェクト名_FRAMEWORKS = UIKit]を追記してください
あとは【ターミナル】から以下のコマンドを実行してdebパッケージを構築すれば終了です
make package
構築したdebパッケージをiPhoneへインストール/実行してみます
うまくいきました
今回はSpringBoard上にアラートを表示させるだけのTweakでしたがバージョンによっての仕様変更やエラー処理をしておかないとセーフモードや無限ループを引き起こしかねません
奥が深い分、十分に注意して作業をしましょう