这个关于Xcode注入的从头开始实现已经构建到一个应用程序中:InjectionIII。app包含在repo中,在状态栏中运行。代码注入允许您在iOS模拟器中增量地更新类方法的实现,而无需重新构建或重启应用程序,从而节省开发人员的时间。您可以通过使用预构建的二进制文件(可从这里下载)来避免代码签名的复杂性。由于某些原因,您可能需要手动将该应用程序从qurantine中移除,否则当您运行该应用程序时,它将报告为损坏:xattr -d com.apple。~ /下载/ InjectionIII.app进行隔离。要使用,复制/链接到/应用程序并运行该应用程序。Injection还希望在path /Appplications/Xcode.app找到当前的Xcode。最后,您需要在应用程序的applicationdidfinishlaunch中添加以下内容之一:
划重点了,我能用它做什么?? 他能帮我什么???
使用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
#if DEBUG
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle"] load];
//for tvOS:
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/tvOSInjection.bundle"] load];
//Or for macOS:
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/macOSInjection.bundle"] load];
#endif
return YES;
}
Or, for Xcode 10:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
#if DEBUG
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/iOSInjection10.bundle"] load];
//for tvOS:
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/tvOSInjection10.bundle"] load];
//Or for macOS:
[[NSBundle bundleWithPath:@"/Applications/InjectionIII.app/Contents/Resources/macOSInjection10.bundle"] load];
#endif
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
}
-(void)injected{
NSLog(@"I've been reinjected: %@", self);
NSLog(@"这里调用修改页面布局 或者属性设置的代码");
self.view.backgroundColor = [UIColor orangeColor];
}