InjectionIII
概述
injectionIII 工具可以动态加载Swift、Objective-C代码到已经在运行的程序中执行,热加载。该项目由John Holdsworth 提供,是一个开源项目
效果
效果来自源项目
injected.gif
安装使用
- App Store 下载 InjectionIII(或到源项目clone 进行构建)
2.Open file -> Project path
3.select File Watcher
openfile.png
4.添加如下代码到项目的AppDelegate
中的func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
Before Xcode 10:(swift)
#if DEBUG
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()
//for tvOS:
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/tvOSInjection.bundle")?.load()
//Or for macOS:
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/macOSInjection.bundle")?.load()
#endif
After Xcode 10:
#if DEBUG
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection10.bundle")?.load()
//for tvOS:
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/tvOSInjection10.bundle")?.load()
//Or for macOS:
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/macOSInjection10.bundle")?.load()
#endif
5.在项目需要修改的代码类中添加如下代码
@objc func injected(){
print("I've been injected: \(self)")
}
6.修改运行中的程序的代码时,只需要按下Command + S
saved, 就所修改的代码就会显示在simulator上
注意⚠️
亲测的该工具适用Simulator
原理
感兴趣的可以看一下这篇文章
网友评论