How to quit/stop Unity in an native iOS app

I am creating an app that uses Unity as a static library, and i need to be able to start and stop Unity as the user pleases.

From inside iOS native when user presses a button it opens Unity, and then from Unity when user presses exit button, i need the Unity App to close and resume native iOS app.

Starting has been easy, using the [startUnit:application], now to quit the app i have been trying to call applicationWillResignActive, and applicationWillTerminate on unityAppController, but after applicationWillTerminate is called i get an error:

extern"C" void ObjectPool_1_Release_m1110976910_gshared (ObjectPool_1_t3970404496 * __this, Il2CppObject * ___element0, constMethodInfo* method)

{

staticbool s_Il2CppMethodIntialized;

if (!s_Il2CppMethodIntialized)

{

il2cpp_codegen_initialize_method (ObjectPool_1_Release_m1110976910_MetadataUsageId);

s_Il2CppMethodIntialized = true;

}

{

Stack_1_t2974409999 * L_0 = (Stack_1_t2974409999 *)__this->get_m_Stack_0();

NullCheck((Stack_1_t2974409999 *)L_0);

int32_t L_1 = (( int32_t (*) (Stack_1_t2974409999 , constMethodInfo))IL2CPP_RGCTX_METHOD_INFO(method->declaring_type->rgctx_data, 4)->methodPointer)((Stack_1_t2974409999 *)L_0, /hidden argument/IL2CPP_RGCTX_METHOD_INFO(method->declaring_type->rgctx_data, 4));

if ((((int32_t)L_1) <= ((int32_t)0)))

{

goto IL_003b;

}

}

and the app crashes, have someone been able to start and stop unity like this?

Thanks!

Hi Zomin,
I’m facing a similar situation. Did you manage to close the Unity part and resume with the native iOS app?
If so, can you give me any hint?
Thanks!

Actually i found out, i can’t quit unity like that. I had to keep both apps running in separate windows, and show one or the other depending on the user’s interaction.

When the unity window was going to get hid, i send a message to Unity so it gets paused and changes scene to a blank scene so it doesnt consume as much resources.

When im going to show Unity again, i send another message to resume Unity, and switch to an active scene.

This is the only way i could make it work!