Aspects icon indicating copy to clipboard operation
Aspects copied to clipboard

Can't hook class methods

Open iamredeye opened this issue 11 years ago • 5 comments

Hello,

I have figured out an issue concerning class method (not instance methods).

I have tried to put this into my code :

[NSJSONSerialization aspect_hookSelector:@selector(JSONObjectWithData:options:error:) withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> info, NSData _data, NSJSONReadingOptions opt, NSError *_error){ NSLog(@"JSONObjectWithData:options:error: before | object:%@ | instance:%@ | class:%@",info,[info instance],[[info instance] class]); } error:NULL];

        [NSJSONSerialization aspect_hookSelector:@selector(JSONObjectWithData:options:error:) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> info, NSData *data, NSJSONReadingOptions opt, NSError **error){
            NSLog(@"JSONObjectWithData:options:error: after | object:%@ | instance:%@ | class:%@",info,[info instance],[[info instance] class]);
        } error:NULL];

The Aspects did not intercept class methods examples set in my AppDelegate for example. Do you know a solution for this issue ?

Thanks

iamredeye avatar Dec 01 '14 09:12 iamredeye

Hmm. Is there any info in the log why this might fail?

steipete avatar Dec 01 '14 10:12 steipete

I have figured out that I have to use the 1.5 version for that. But it seems not working on arm64... Do you have any news when It could be released for arm64 devices / simulators ?

iamredeye avatar Dec 01 '14 11:12 iamredeye

Never found the time to dig into that. PR's welcome :)

steipete avatar Dec 01 '14 11:12 steipete

The version 1.4 works great on arm64 but does not contain Class Hook methods. The 1.5 doesnt work on arm64 but contains Class Hook Methods. Is there a way to add just the needed code from 1.5 to the 1.4 to just add on it the class hook methods functionnalities ? I think the problem is with trampoline on arm64

iamredeye avatar Dec 01 '14 15:12 iamredeye

Again, I very much welcome pull requests. Currently 1.4 works for me as I use Apects for testing/mocking only - if this changes I'll put it more work.

steipete avatar Dec 01 '14 17:12 steipete