johnno1962 / injectionforxcode

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

Getting Notified on bundle injection #55

Closed s4cha closed 9 years ago

s4cha commented 9 years ago

Hey,

First of all thanks for this amazing library, it totally rocks!

We encountered a small issue though, we tried to get notified on bundle injection with no luck. We tried modifying BundleInjection.h inserting an NSNotification but it looks like it does not take our changes into account. Could you give us a hint on how to get notified within the app when an injection occurs?

Thanks a lot in advance :)

#endif
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
    if ( notify & INJECTION_NOTSILENT ) {
        [[NSNotificationCenter defaultCenter] postNotificationName:"TEST" object:nil];
        NSString *msg = [[NSString alloc] initWithFormat:@"Class '%@' injected.",
                         NSStringFromClass(oldClass)];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"TEST Loaded"
                                                        message:msg delegate:nil
                                              cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert performSelector:@selector(injectionDismiss)
                    withObject:nil afterDelay:1.];
#ifndef INJECTION_ISARC
        [alert release];
        [msg release];
#endif
s4cha commented 9 years ago

We finally made it work by using the same technique, but modifying BundleInjection.h in ~/Library/Application\ Support/Injection\ Plugin/injectionforxcode/InjectionPluginLite/Classes/BundleInjection.h.

Once modified, we needed to build again : /Users/sacha/Library/Application\ Support/Injection\ Plugin/injectionforxcode/InjectionPluginLite/InjectionPlugin.xcodeproj

And Tada! it worked :) Are you planning to make such a notification available in future releases ?

Thank you so much,

Sacha

johnno1962 commented 9 years ago

Hi, Isn’t there already a notification in the code: [[NSNotificationCenter defaultCenter] postNotificationName:kINNotification object:injectedClasses]; Let me know if this isn’t working!!

s4cha commented 9 years ago

Indeed! We were so busy looking for the UIAlert view code that we missed the NSNotificationCenter call :) That's perfect !