Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用aspects时 如果controller自己实现了forwardInvocation不崩溃 #132

Closed
askday opened this issue Nov 4, 2015 · 13 comments
Closed

Comments

@askday
Copy link

askday commented Nov 4, 2015

- (void)forwardInvocation:(NSInvocation *)anInvocation
{
    [super forwardInvocation:anInvocation];
}

注掉就崩溃,是不是能查查原因?

NSMethodSignature *methodSignature = [slf methodSignatureForSelector:origForwardSelector];
NSInvocation *forwardInv= [NSInvocation invocationWithMethodSignature:methodSignature];
被打补丁对象如果自己实现了forwardInvocation,那么这里的执行是正确的,没有实现就崩溃了
是不是说明methodSignature没有获取到NSObject中相关的方法,如何能获取NSObject的呢?

@bang590
Copy link
Owner

bang590 commented Nov 4, 2015

https://github.com/bang590/JSPatch/blob/master/JSPatch/JPEngine.m#L422-L428
只要把这段改为

SEL origForwardSelector = @selector(ORIGforwardInvocation:);
if (class_respondsToSelector(object_getClass(slf), origForwardSelector)) {
            NSMethodSignature *methodSignature = [slf methodSignatureForSelector:origForwardSelector];
            NSInvocation *forwardInv= [NSInvocation invocationWithMethodSignature:methodSignature];
            [forwardInv setTarget:slf];
            [forwardInv setSelector:origForwardSelector];
            [forwardInv setArgument:&invocation atIndex:2];
            [forwardInv invoke];
}

就不会崩溃,但 JSPatch 和 Aspects 对这个类里方法的替换会因为先后顺序导致其中一个库不生效。

@askday
Copy link
Author

askday commented Nov 5, 2015

多谢 bang,不过这段改动只是加了个判断,其实还是会崩溃的
晚点我弄个demo看看

demo:https://github.com/askday/JSPatchDemo.git

@lubaoyilang
Copy link

加了判断后 不崩溃了,但是没有达到目的,我也查出来了,之前我那个 Viewdidload问题,因为我用的是你平台的 SDK,没有代码,所以找不到原因,后来换成jspatch源码,发现我也崩溃在这里。。项目中 没有使用 aspects,但是接入的第三方可能有用到。。有什么办法嘛?

@lubaoyilang
Copy link

我除非 在 所有第三方调用的 后边 来调用 jspatch,如果这样,第三方库有些功能会失效。

@bang590
Copy link
Owner

bang590 commented Nov 5, 2015

@askday 这个崩溃是另一个原因了,aspects替换的loadView方法走到了JSPatch的逻辑里,导致没正常调用
@lubaoyilang 没找到完美的解决方法

@lubaoyilang
Copy link

@bang590 SDK 可以增加 一下判断嘛?我用的是你平台,嘿嘿

@askday
Copy link
Author

askday commented Nov 6, 2015

可以借鉴aopaspect库下,这个使用的时候跟aspect不冲突,通过保存当前class对象来切入,多谢bang及时回复。

@wanyakun
Copy link

我项目中使用了aspects, 前天更新的类库,在这里是会崩溃

@hetachen
Copy link

原来是因为aspects库的原因,我找了半天...不知道有没有什么稳妥的办法

@qiusuo8
Copy link

qiusuo8 commented Jan 26, 2016

static void JPForwardInvocation(id slf, SEL selector, NSInvocation *invocation)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
SEL origForwardSelector = @selector(ORIGforwardInvocation:);
NSMethodSignature *methodSignature = [slf methodSignatureForSelector:origForwardSelector];
if (!methodSignature) {
NSCAssert(methodSignature, @"unrecognized selector -ORIGforwardInvocation: for instance %@", slf);
return;
}
NSInvocation *forwardInv= [NSInvocation invocationWithMethodSignature:methodSignature];
[forwardInv setTarget:slf];
[forwardInv setSelector:origForwardSelector];
[forwardInv setArgument:&invocation atIndex:2];
[forwardInv invoke];
return;
#pragma clang diagnostic pop

改成
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
SEL origForwardSelector = @selector(ORIGforwardInvocation:);
if (class_respondsToSelector(object_getClass(slf), origForwardSelector)) {
NSMethodSignature *methodSignature = [slf methodSignatureForSelector:origForwardSelector];
if (!methodSignature) {
NSCAssert(methodSignature, @"unrecognized selector -ORIGforwardInvocation: for instance %@", slf);
return;
}
NSInvocation *forwardInv= [NSInvocation invocationWithMethodSignature:methodSignature];
[forwardInv setTarget:slf];
[forwardInv setSelector:origForwardSelector];
[forwardInv setArgument:&invocation atIndex:2];
[forwardInv invoke];
}
return;
#pragma clang diagnostic pop

我在项目中使用了,JSPatch 和 Aspects 两个都生效了,

@askday
Copy link
Author

askday commented Jan 26, 2016

加了个判断 貌似没什么效果

@fighterLS
Copy link

我也遇到这个问题了,项目里没有Aspects,加了@WisdomZhao 给的判断可以解决问题

@bang590
Copy link
Owner

bang590 commented Apr 2, 2016

aspects问题最新代码已解决

@bang590 bang590 closed this as completed Apr 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants