I create a simple example trying to get the first argument of the method, if it works I plan to extend it to any number of arguments:
+ (void)simpleTest:(NSInteger)teamId {
unsigned int argumentCount = method_getNumberOfArguments(class_getClassMethod([self class], _cmd));
for (unsigned int i = 2; i < argumentCount; i++) {
const char *argumentType = method_copyArgumentType(class_getClassMethod([self class], _cmd), i);
if (strcmp(argumentType, @encode(NSInteger)) == 0) {
NSInteger argumentValue = *((NSInteger *)(((uintptr_t)self) + sizeof(void *) * i));
NSLog(@"Argument %d: %ld", i - 1, (long)argumentValue);
}
free((void *)argumentType);
}
}
I call it like this:
[self simpleTest:22];
the log print:
Argument 1: 140703128941760
I think the problem happens at the piece of code where I want to get 'argumentValue', but I don`t know how to fix it.