這個關于Xcode注入的從頭開始實現(xiàn)已經(jīng)構建到一個應用程序中:InjectionIII肖抱。app包含在repo中唧领,在狀態(tài)欄中運行窝爪。代碼注入允許您在iOS模擬器中增量地更新類方法的實現(xiàn)唇敞,而無需重新構建或重啟應用程序瓜喇,從而節(jié)省開發(fā)人員的時間。您可以通過使用預構建的二進制文件(可從這里下載)來避免代碼簽名的復雜性节沦。由于某些原因姨涡,您可能需要手動將該應用程序從qurantine中移除史煎,否則當您運行該應用程序時谦屑,它將報告為損壞:xattr -d com.apple。~ /下載/ InjectionIII.app進行隔離篇梭。要使用氢橙,復制/鏈接到/應用程序并運行該應用程序。Injection還希望在path /Appplications/Xcode.app找到當前的Xcode很洋。最后充蓝,您需要在應用程序的applicationdidfinishlaunch中添加以下內(nèi)容之一:
劃重點了,我能用它做什么?? 他能幫我什么???
使用
- (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(@"這里調(diào)用修改頁面布局 或者屬性設置的代碼");
self.view.backgroundColor = [UIColor orangeColor];
}