Closed snlo closed 5 years ago
Hi, last time I looked RAC uses __unsafe pointers which doesnβt work well with the βsweepβ that implements the -(void)injected method. Youβll have to try using the INJECTION_BUNDLE_NOTIFICATION notification which is sent each time you inject instead.
Subscribing to the INJECTION_BUNDLE_NOTIFICATION notification is indeed valid. There is also a workaround in which the previously subscribed signals are cleaned up in the function injected because they appear to be injected with duplicate subscriptions.
`- (void)injected { NSLog(@" - - %s",func);
[self.view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:UIControl.class]) {
UIControl * control = (UIControl *)obj;
NSLog(@" -- %@",control.allTargets);
[control.allTargets enumerateObjectsUsingBlock:^(id _Nonnull objx, BOOL * _Nonnull stop) {
[control removeTarget:objx action:@selector(sendNext:) forControlEvents:UIControlEventTouchUpInside];
}];
}
}];
[[self.buttonTest rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
NSLog(@"--injected ok--");
self.labelTest.text = @"button test";
}];
}`
Xcode10.2 InjectionIII v.1.51
#import <ReactiveObjC.h>
`- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view.}
(void)configureUserInterface {
[[self.buttonSaveCodeImage rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) { NSLog(@" - -- 112-12--1-2-0-0-0-0-0-4u");
}];
}
- (void)injected { self.view.backgroundColor = [UIColor blackColor]; [self.buttonSaveCodeImage setTitle:@"π" forState:UIControlStateNormal];
}
Thread 1: EXC_BAD_ACCESS (code=1, address=0x4f915cf38d20)
π Compiling /Users/snlo/Desktop/Demo/QQQ/QQQ/ajeivnweqornviw/OpenShareDistributionPromotionViewController.m π Loading .dylib ... objc[6372]: Class OpenShareDistributionPromotionViewController is implemented in both /Users/snlo/Library/Developer/CoreSimulator/Devices/E9DBA0FA-06D3-4F61-840D-A814F163F387/data/Containers/Bundle/Application/E9618335-339E-4AFB-8461-63864B9CD143/QQQ.app/QQQ (0x1048f6780) and /Users/snlo/Library/Containers/com.johnholdsworth.InjectionIII/Data/eval102.dylib (0x12c3ff5c8). One of the two will be used. Which one is undefined. π Loaded .dylib - Ignore any duplicate class warning ^ 2019-04-01 17:05:28.024 QQQ[6372:4243698] hello world (lldb) `