johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.56k stars 565 forks source link

Injected code does not execute with Xcode 6 #32

Closed objectiveSee closed 10 years ago

objectiveSee commented 10 years ago

I have been using Xcode Injection for 2 years now and have a license for it. I love it, but it's no longer working for me. I have uninstalled and re-installed it multiple times; using Alcatraz, from the Installer, and from the source code.

In a simple example: I have a button that shows a UIAlertView. I am changing the text of the alert and then hitting "Inject Source". In the Xcode 6 console I see:

(lldb) p (void)[[NSBundle bundleWithPath:@"(null)/InjectionLoader.bundle"] load]
(lldb) c

Afterwards I tap my button again and the UIAlertView shows up displaying the old text and not the new text. Any thoughts as to what is going on @johnno1962?

Thanks! :beers:

johnno1962 commented 10 years ago

Hi, I can’t replicate your problem but I’d bet it is sokmething to do with a missing nib file. The two bits of code to check are:

NSString *loader = [NSString stringWithFormat:@"p (void)[[NSBundle bundleWithPath:@\""
                    "%@/InjectionLoader.bundle\"] load]", self.client.scriptPath];

and in INClientPluginClientController:

self.scriptPath = [[NSBundle bundleForClass:[self class]] resourcePath];

for some reason this is not getting set which would be the case if the nib didn’t load. Check for the following in your console:

if ( ![NSBundle loadNibNamed:@"INPluginMenuController" owner:self] )
    NSLog( @"INPluginMenuController: Could not load interface." );

Without theInjectoinLoader.bunle injection won’t work.

objectiveSee commented 10 years ago

I do not see INPluginMenuController: Could not load interface. in the console logs for my App when I inject. I am not sure what you mean by checking code in INClientPluginClientController. How do I check it?

For what it's worth, I have tested Injection on multiple projects and none of them were able to inject new code. All show the same p (void)[[NSBundle bundleWithPath:@"(null)/InjectionLoader.bundle"] load] console output.

johnno1962 commented 10 years ago

Injection will not work at all until you work out why there is a null in (null)/InjectionLoader.bundle. You can see the aeas of code involved if you build from source. I’m afraid I can’t replicate the problem this end with any version of Xcode. Please put in some NSLogs to try build and restart Xcode to work out what is going on. in particular to see if the following is called:

self.scriptPath = [[NSBundle bundleForClass:[self class]] resourcePath];

I appreciate the fact you have a license but there is not much mor I can do. The code is not that involved.

objectiveSee commented 10 years ago

I see now. Building from source updates ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin. Hopefully I can figure it out from here.

objectiveSee commented 10 years ago

The following steps fixed this issue:

  1. Uninstall plugin via Alcatraz
  2. Clear derived data for Xcode Injection (This step is very important)
  3. Reinstall plugin via building from source (clone + build).

Now I am dealing with new issues: Injection Bundle errors due to missing headers that are included in my project's .pch. See https://github.com/johnno1962/injectionforxcode/issues/7

johnno1962 commented 10 years ago

Great, hapy to hear you’ve managed to resolve this problem now. I’ve not had any problems installing injection from Alcatraz but I know there are people that have. Your header path problem you need to resove by editing the “Header Search Paths” in the “bundle project” injection creates in the normal way.