Building for IOS

Building for IOS

We are using Reflection to localize the properties (or fields) If you are targeting IOS, you may encounter the situation, that property can be stripped (removed) from the build. If you use only properties, marked as recommended (prefixed [RECOMMENDED]), you have nothing to worry about However if you are using another properties, you want to force compiler to include them in the build. There are couple of methods how to do it, the most straightforward is: to make direct references in the code.

Create a simple class, add private method, reference the properties you are using and add it to one of your scenes. After that add link.xml to you project with following content

<linker>
       <assembly fullname="Assembly-CSharp.dll">
               <type fullname="PreventIosFromStripping" preserve="all"/>
       </assembly>
</linker>

More info about link.xml can be found here

Here is an example:

public class PreventIosFromStripping : MonoBehaviour
{
    private void Unused()
    {
        GetComponent<MyComponent>().myProperty1 = null;
        GetComponent<MyComponent>().myProperty2 = null;
        //etc.
    }
}