I use the standard swizzling method on ARMv7 iOS devices and it works great for me.
But when I compile my code for arm64 - it cannot call the original method from the new method
The main purpose of my swizzling is to use a parameter from the internal method of my application in another method.
I have an original method -(void)insertdata:(id)text , and I want to change it to -(void)patchedCall:(id)text and call the original method in a new method.
the code:
static IMP sOriginalImp = NULL; @interface TextOverrides: NSObject +(void)load; -(void)patchedinsert:(id)text; @end @implementation TextOverrides +(void)load { //Get Implementation of original method Class originalClass = NSClassFromString(@"DataViewController"); Method originalMeth = class_getInstanceMethod(originalClass, @selector(insertdata:)); //Save original method implementation sOriginalImp = method_getImplementation(originalMeth); // Get implementation of replacement method Method replacementMeth = class_getInstanceMethod(NSClassFromString(@"TextOverrides"), @selector(patchedCall:)); //Replace methods method_exchangeImplementations(originalMeth, replacementMeth); } -(void)patchedCall:(id)text { @synchronized(self){ //Call of original method that we save sOriginalImp(self, @selector(insertdata:), text); //Make our code for argument "text" printf("Here is data%s\n", [text UTF8String]); } } @end
Code crash when calling source method in arm64 architecture:
//Call of original method that we save sOriginalImp(self, @selector(insertdata:), text);
How can I improve my code to work on both armv7 and arm64?
Yakov source share