Open wangqianjun opened 8 years ago
Hi, if you post some code I can help.
Steipete, I create a Category for UIViewcontroller, and have a Class method viewDidloadLogging:
In my demo AppDelegate,
There are no problems using?
+1
+1's don't help. Somebody who digs in and figures out what fails would help though. Thanks!
So that question answer is what,Steipete?^.^
This is the problem of execution order of [UIViewController viewDidLoad] and [UIViewController viewDidloadLogging]. Please make sure [UIViewController viewDidloadLogging] is invoked before [UIViewController viewDidLoad].
I got the same issue while hooking viewDidLoad selector of UIViewController class. I can't call the block I provided but "dealloc" is working.
Can you figure out the solution?
Thanks a lot.
The code as following:
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
// Ignore hooks when we are testing.
if (!NSClassFromString(@"XCTestCase")) {
[[LogManager sharedInstance] logViewControllerLifeCycle];
}
//...other code
}
(void)logViewControllerLifeCycle
{
[UIViewController aspect_hookSelector:@selector(viewDidLoad)
withOptions:AspectPositionBefore
usingBlock:^(id
}
Hi everyone, I made it. The root cause is that "aspect_isCompatibleBlockSignature" verifies that argument count of blockSignature and methodSignature,and if not matched ,nil returned. You can see these code : if (blockSignature.numberOfArguments > methodSignature.numberOfArguments) { signaturesMatch = NO; //You will go here if wrong block parameters provided as above. }else {
Now ,we can correct it by changing [UIViewController aspect_hookSelector:@selector(viewDidLoad) withOptions:AspectPositionBefore usingBlock:^(id info, BOOL animated) { to [UIViewController aspect_hookSelector:@selector(viewDidLoad) withOptions:AspectPositionBefore usingBlock:^(id info) {
It works now for "viewDidLoad".
Hi @Steipete, I suggest to throw an exception here for developers to correct it to right things.
Thanks.
How can i use AspectPositionInstead option replace viewDidLoad method? Any help would be appreciated.
[MySubViewController aspect_hookSelector:@selector(viewDidLoad) withOptions:AspectPositionInstead usingBlock:^(id
Hi Steipete, why can't hook viewDidLoad (UIViewController) ??
Error: Aspects: Blog signature <NSMethodSignature: 0x7fbc8bd35740> doesn't match <NSMethodSignature: 0x7fbc8bf0cc40>.
Please help~
Thank u.