地址:https://github.com/johnno1962/injectionforxcode
Injection热加载只对模拟器有效,对真机无效
第一步:App Store 搜索 InjectionIII 下载 运行即可
第二步:在AppDelegate.m中,didFinishLaunchingWithOptions方法里添加
#if DEBUG
// iOS
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle"] load];
#endif
第三步:打开InjectionIII ,open project找到项目所在地
第四步:xcode运行代码,commend+r
背景:xcode12.2,模拟器选择iPhoneX(12.0)
运行报错:Error loading /Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection: dlopen(/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection, 265): Library not loaded: @rpath/libswiftCore.dylib Referenced from: /Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection Reason: no suitable image found. Did find: /usr/lib/swift/libswiftCore.dylib: mach-o, but not built for iOS simulator
解决方法:终端运行 open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/swift
找到xcode自带模拟器,选择模拟器iphone11(14.2)。
调试阶段:
-(void)injected{
NSLog(@"我已经injected");
[self viewDidLoad];
}
我们需要监听的页面里面重写这个方法即可