0

Hi I am building an application for iOS using Unity3D. I am using UnityWebRequest to fetch data from my server (POST request). It works in my Unity Editor but not on my iPhone. However, I can actually see the JSON data I want in the debugging window in XCode, which is below,

You are using download over http. Currently unity adds NSAllowsArbitraryLoads 
to Info.plist to simplify transition, but it will be removed soon. Please 
consider updating to https.
Unhandled Exception: System.NotSupportedException: 
/Users/builduser/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/DynamicMethod.cpp(26) : Unsupported internal call for IL2CPP:DynamicMethod::destroy_dynamic_method - System.Reflection.Emit is not supported.
  at System.Reflection.Emit.DynamicMethod.Finalize () [0x00000] in <filename unknown>:0 
UnityEngine.UnhandledExceptionHandler:PrintException(String, Exception)
UnityEngine.UnhandledExceptionHandler:HandleUnhandledException(Object, UnhandledExceptionEventArgs)

(Filename:/Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineDebugBindings.gen.cpp Line: 37)
(MY JSON DATA)

So my JSON data display correctly in the debugger info, but why I cannot get it from my code? Like string data = MY_JSON_DATA and let me to parse?

I have checked ATS and this answer but it seems not work. Am I on the correct direction?

UPDATE: My Unity is 5.3.4p6, XCode: 7.3.1, iOS: 9.3

UPDATE2: JSON API: Newtonsoft.JSON, WebRequest: UnityWebRequest

Community
  • 1
  • 1
milanow
  • 159
  • 1
  • 13
  • What Unity version? What iOS version? What Json API are you using? These are important to get a reasonable answer. – Programmer Jul 16 '16 at 05:15
  • @Programmer Thanks I have added the version I am using – milanow Jul 16 '16 at 05:19
  • Ok.What json API are you using? How are you reading the received json data from server? – Programmer Jul 16 '16 at 05:21
  • @Programmer If you mean in the client, I use Newtonsoft.json to deserialized my JSON string. I simply send a POST request to my API by UnityWebRequest.send(). and get content from unityWebRequest.downloadHandler. – milanow Jul 16 '16 at 05:26
  • So what's the problem? Is it crashing? – Programmer Jul 16 '16 at 05:28
  • @Programmer The app can be built successfully, but I cannot get my json string in the json (no results on my screen). However since I am building and running with XCode, I can see my JSON data in the Debug window of XCode. – milanow Jul 16 '16 at 05:31
  • @Programmer Thanks for patience – milanow Jul 16 '16 at 05:33
  • Np. Unity has built in Json Serializer. Post example of what the working Json received from the server looks like. Run it in the editor then copy and post it in your question. – Programmer Jul 16 '16 at 05:33
  • @Programmer Ok I may use Unity's built-in JSON serializer and see what happens first. Thanks! – milanow Jul 16 '16 at 05:44
  • @Programmer Solved it, it seems Newtonsoft.JSON not compilable with iOS device. That's why I cannot deserializing properly. And Unity's JSONUtility also not work for iOS. What I use is LitJson instead. It works both in Editor and iOS. Thanks! – milanow Jul 16 '16 at 22:44
  • **"And Unity's JSONUtility also not work for iOS"** This is not true. With 5.4 version,Unity JsonUtility works on iOS. That's fine if LitJson solved your problem. As long as you got it working – Programmer Jul 16 '16 at 22:59
  • @Programmer Maybe it is because I am using Unity3D 5.3.4p6 – milanow Jul 17 '16 at 00:36

1 Answers1

0

Although a workaround for the problem was found in the comments, I'll mention here what this error message means. The error which occurred was:

Unhandled Exception: System.NotSupportedException: /Users/builduser/buildslave/unity/build/Tools/il2cpp/il2cpp/libil2cpp/icalls/mscorlib/System.Reflection.Emit/DynamicMethod.cpp(26) : Unsupported internal call for IL2CPP:DynamicMethod::destroy_dynamic_method - System.Reflection.Emit is not supported.

The IL2CPP transpiler works ahead-of-time (AOT) only. So it cannot create code at runtime, hence, System.Reflection.Emit is not supported as the error message indicates.

Some JSON utilities emit code at runtime, but many have an AOT-friendly mode that does not. In this case, the workaround "works" because the JSON utility that is used now is AOT-friendly.

Josh Peterson
  • 2,299
  • 19
  • 21