Version: Unity 6.7 Alpha (6000.7)
Language : English
Introduction to native plug-ins on iOS
Call native plug-ins for iOS

Create a native plug-in for iOS

Create a native plug-in for iOS and import it into your Unity project.

Define an extern method

For each native function you want to call, define an extern method in the C# file as follows:

Note: Use "__Internal" as the library name when your native code is built into the same binary as the Unity runtime. For example, a statically linked plug-in. If your native code is in a dynamic library (.dylib), use the library name instead. For example, "MyPlugin" for MyPlugin.dylib.

[DllImport ("__Internal")]

private static extern float FooPluginFunction();

Use C linkage to prevent name mangling

If you use C++ (.cpp) or Objective-C++ (.mm) for your plug-in, declare functions with C linkage to avoid name mangling:

extern "C" {
  float FooPluginFunction();
}

C or Objective-C plug-ins don’t require C linkage as they don’t use name mangling.

If you use Swift for your plug-in, use the @_cdecl attribute to export functions with C linkage and avoid name mangling:

@_cdecl("FooPluginFunction")
func AnythingFooPluginFunction() -> Float {
    return 3.14
}

Import your native plug-in into your Unity project

Add your native source files to your project’s Assets folder.

Configure plug-in settings

Use the Inspector window to configure your plug-in so Unity includes it in the generated Xcode project. Refer to Configure a plug-in for iOS with the Inspector window for details.

Additional resources

Introduction to native plug-ins on iOS
Call native plug-ins for iOS