Call native plug-ins for iOS
Wrap native code in C# layer to only run code when using an iOS device.
Read time 1 minuteLast updated 12 days ago
Your app can only call iOS native plug-ins when deployed on an actual device. Wrap all native code methods with an additional C# code layer to only call native methods when the app is running on a device. Store this C# file in your Project's folder.
AssetsThis C# layer can use platform conditional compilation or check . For code running in the Unity Editor, return placeholder values.
Application.platformRefer to the following sections for simple implementations of these methods. For a more detailed implementation, refer to Unity native plug-in example for iOS.
Use conditional compilation
Platform dependent compilation is faster than as it's evaluated at compile time, rather than runtime.
Application.platformUse the following to implement conditional compilation:
void MyMethod(){#if UNITY_IOS && !UNITY_EDITOR CallNativeMethodImplementation();#else CallEditorMethodImplementation();#endif}
Check Application.platform
Use the following to implement and return placeholder values in the Editor:
Application.platformvoid MyMethod() { if (Application.platform != RuntimePlatform.OSXEditor) { return _GetLookupStatus(); } else { return "Done"; }}