Use Mono 2.X on Ubuntu 14.04 LTS

Unfortunately, I had to use the Mono which version is 2.X in my project. It’s very old, released in 2012! So I installed it on Ubuntu 16.04 LTS from source and do make. Then the error occurred in doing make like this:

./.libs/libmini-static.a(libmini_static_la-mini.o): In function `mono_get_jit_tls_offset':
/home/vagrant/mono-2.11.4/mono/mini/mini.c:2506: undefined reference to `mono_jit_tls'
/home/vagrant/mono-2.11.4/mono/mini/mini.c:2506: undefined reference to `mono_jit_tls'
collect2: error: ld returned 1 exit status
Makefile:1351: recipe for target 'mono' failed
make[4]: *** [mono] Error 1
make[4]: Leaving directory '/home/vagrant/mono-2.11.4/mono/mini'
Makefile:1209: recipe for target 'all' failed
make[3]: *** [all] Error 2
make[3]: Leaving directory '/home/vagrant/mono-2.11.4/mono/mini'
Makefile:344: recipe for target 'all-recursive' failed
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory '/home/vagrant/mono-2.11.4/mono'
Makefile:419: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/vagrant/mono-2.11.4'
Makefile:344: recipe for target 'all' failed
make: *** [all] Error 2

So I ended up using Ubuntu 14.04 LTS for Mono 2.X.

The error might occur by the libraries that are gcc or something related to compilation.

Use native code on iOS with Unity Native Code in the Unity

First, write native code you used for iOS. Read this document

I needed to write native code for the In-App Purchase on iOS.

Then, just put your native code in the Assets/Plugins/iOS directory. The hierarchy like this;

For example, using Objective-C, Assets/Plugins/iOS/sample.m and Assets/Plugins/iOS/sample.h.

Build on Unity

In File > Build Settings, switch iOS platform and then click Build and Run. Next, when the build complete, launch Xcode and build the project created by Unity on it automatically.

Build on Xcode

Initial build might occur a signing problem that is Team is None. To solve this problem, just select a team in the pull-down menu of the team. Automatically sign to your app as the team you selected.

Click the build button top left of the Xcode window!

Receive a callback as JSON from an iOS code

Set Game Object on a Unity script before call the native code

var gameObject = GameObject.Find("PurchaseHandler");
            if (gameObject != null) return;

            gameObject = new GameObject("PurchaseHandler");
            if (UnityEngine.Application.isPlaying)
            {
                GameObject.DontDestroyOnLoad(gameObject);
            }

            gameObject.AddComponent<PurchaseHandler>();

Call UnitySendMessage on iOS

sample.m

void GetProductList(const char* json)
{
    ...
    NSString *jsonString = @"{list: [ ... ]}"
    UnitySendMessage([@"PurchaseHandler" UTF8String], [@"onSuccess" UTF8String], [jsonString UTF8String]);
}

Receive a message of UnitySendMessage

public class PurchaseHandler : MonoBehaviour
    {
         private IEnumerator onSuccess(string message)
        {
            yield return doSomething(message);
        }
}