I have encountered a problem where the reflection method GetMethod is not returning a static method for a class. This is only going wrong on an actual iphone; on the simulator it is working correctly. I have tried the following:
MethodInfo methInfo = _type.GetMethod (methodName);
and
MethodInfo methInfo = _type.GetMethod (methodName, System.Reflection.BindingFlags.Static);
but neither of these return the method specified in methodName. The specified method does exist as shown by the fact that it works on the simulator. I have confirmed with the debugger that my member variable _type does contain the correct class type reference. The methods that I am trying to retrieve are declared as public in the class.
Has anyone encountered this before or know why this would work on the simulator but not on the actual iphone?
Reflection, although not fully operational on iOS, works. The problem is that the linker is activated on the configuration for the device and is cutting off the method since it is not being used. The linker cannot "see" reflection calls.
If it is a custom object, decorate it with the PreserveAttribute:
[Preserve(AllMembers=true)]
public class MyClass
{}
If it is an object from the SDK, you have two choices:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With