A better way to integrate Unity3D with a native iOS app

A better way to integrate Unity3D within a native iOS app

Update: I’ve created a new tutorial for Xcode 7 & Unity 5.

Last year I published a blog post about how to integrate Unity3D within a native iOS application.

Last week I found a better way to integrate Unity3D within a native iOS app, which also eliminates some issues with my previous version.  Because it’s quite a long explanation to do and I noticed in my previous blog post that not everything was crystal clear, I’ve made a video tutorial how you can achieve this.

I hope this can help some of you guys out, because integrating Unity3D within a native iOS app isn’t that easy, but I’m really happy with the setup that I have right now.

Prerequisites

The version of Unity that I use is 4.6.7f1 and Xcode 6.4.

Video tutorial: integrate Unity3D within a native iOS app

You can check out the video on Vimeo – Add Unity3D in native iOS application. If you have any questions, just put them in the comments, or contact me via Twitter. I hope you know understand how to integrate Unity3D within a native iOS app.

  • Pingback: Sandbox Unity app in existing iOS app | the-nerd()

  • Pingback: Add Unity3D in a native iOS application | the-nerd()

  • Thanks for this!

    FWIW, I found that I also needed to include il2cpp_output in my enclosing project in order to avoid linker errors with the methods referenced by RegisterMonoModules.cpp. (RegisterAllClasses, RegisterAllClassesIPhone, RegisterAllStrippedInternalCalls). I was using Unity 4.6.8f1 and XCode 6.4.

    • Thanks for mentioning, I haven’t upgraded to 4.6.8 yet as it has only been released 5 days ago! I gonna check it out.

      • oops my bad!!!

        i was using ‘I’ for India instead of ‘l’ for london

        in ‘-weak-ISystem’

        it is fixed for good now…

        Thanx a ton… Frederick

  • iam still getting the linker error..
    even after putting the dash …

    unknown argument: ‘-weak-ISystem’

    Can u suggest whats wrong…??

    • The correct flags for ‘other linker flags’ are:
      -weak_framework CoreMotion -weak-lSystem

      If that doesn’t work, it could be you have not linked another library correctly.

      • oops my bad!!!

        i was using ‘I’ for India instead of ‘l’ for london

        in ‘-weak-ISystem’

        it is fixed for good now…

        Thanx a ton… Frederick..

    • Nitesh Singh

      Hi, just wanted to know if you were able to resolve this ‘Unkown Argument’ error?

  • Wang Han-Yu

    Hi! it work well with my iPhone5, but when I change the platform to iPhone6 plus, there are lots of link error 🙁 any idea?

    • I only need to integrate Unity within iPad apps, so I’m afraid I won’t be able to help you out. Although it would be weird that there is a difference between an iPhone 5 & iPhone 6 plus (apart from it’s screen size).

    • Wang Han-Yu

      Oops, I just figured out it’s not about the iPhone 5 or 6.
      It’s about real machine or virtual machine. I was testing iPhone6 plus with virtual simulator.
      I did more test and found my real iPhone 5 works well, but the virtual iPhone 5 got link error too, Weird o_O

  • Mojtaba Tabatabaie

    Thanks very much for your great tutorials. I have a vuforia project which I want to import in my other ios project. I tried your tutorial , but in the end I get errors on POPVector.h, POPAnimationRuntime.h, POPAnimationInternal.h , POPPropertyAnimation.h
    There are 19 errors in the project. for example in POPVector.h I’m getting below errors:
    -Lexical or Preprocessor Issue: Too many arguments provided to function-like macro invocation
    -Semantic Issue: No type named ‘shared_ptr’ in namespace ‘std’
    -Parse Issue : Expected unqualified-id
    -Semantic Issue : No type named ‘shared_ptr’ in namespace ‘std’
    -Parse Issue : Expected unqualified-id

    there must be something wrong which gives all these errors in these POP… files.
    I’ll appreciate if you can help me with this.
    Thanks very much for your help

  • luojie

    I have follow you by doing this ,it can built successed! but it broke at :
    UIApplicationMain(argc, argv, nil, [NSString stringWithUTF8String:AppControllerClassName]);

    if i can’t do it right now , i could lost my job..

  • luojie

    by hte way , I want to change it to my swift work . how i do ? is it can ?

  • luojie

    Is IT can run with swift ? I want to put it to my swift work . but I can . please help me .

    • It should be possible to do this with Swift, although I haven’t tried it yet. So I’m afraid I can’t help you with that at this time!

  • Mojtaba Tabatabaie

    Thanks very much for your great tutorials. I have a vuforia project which I wanted to add to an existing ios project. I followed the tutorial and fixed many errors and it is built successfully. but when I run it on the device it throws an exception on UnityAppController.mm and tells that “createViewHierarchyImpl is deprecated and will not be called. Override willStartWithViewConroller.” As I searched it seemed it is because some of the updates in new versions of ios.
    I’m using unity5.1.2f and Xcode 6.4 running it on an ios 8.4.1 device.
    I’ll appreciate if you can help me with this.
    Thanks very much

    • They probably have deprecated the createViewHierarchyImpl method in Unity5. I’m still using Unity 4.6, so I’m afraid I can’t help you at the moment!

  • Roger Ingouacka

    Hi !
    Thanks for you tutorials ! Is it possible to have all the source code ?

  • RakeshKasinathan

    Hi!
    First of all i have to thank for the Above Video
    I have tried with the video in Build Phase->Runscript i had include the following script,

    rm -rf “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Data”

    cp -Rf “$PROJECT_DIR/../../Heart3Ds_NoAR/Data” “$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Data”

    I have an build error:

    Cp: “/Users/user/Desktop/Heart3Ds_NoAR/Data”: No such file or directory

    what seems to be wrong.

    • 巩昊

      The problem you solved?

      • RakeshKasinathan

        Ya solved.

  • Hi @thenerd_be:disqus, thanks for the tutorials on this subject, I’ve found them very educational! Have you tried doing this in XCode 7? I’m getting a “Thread 1: signal SIGABRT” error after removing the storyboards from the native xcode project.

    Cheers!

    • You probably have forgotten to delete the key Main storyboard file base name in your Info.plist. If Xcode sees this key in that file, it will try to load that Storyboard. Just delete it and you should be fine.

      Cheers,
      Frederik

      • ram

        I just tried to build the sample arkit project – vbut just get a black screen after tyeh unity logo – please see screen grab of Xcode .Please give me step by step how to build settings,camera settings.thanks in advance.

  • Babybet

    Hi! Thanks for the tutorial. I have an issue. Whatever I do, this error persists
    “ld: library not found for -liPhone-lib
    clang: error: linker command failed with exit code 1 (use -v to see invocation)”.
    I am not able to solve it. I’m using unity 5 and xcode 7.

    • Hi,

      I haven’t had the chance to test it with Unity 5 yet. As far as I know, we’ll stick to Unity 4 for a little while longer.

      Sorry I won’t be able to help you with Unity 5!

      • Babybet

        Hi, its okay. Thanks for replying.

        • Lucas

          Hi, did you finally found a solution for that ? I do have the same error…

          • Babybet

            Well, I’m planning to try with unity 4. I don’t know whether it is the problem with the new version of xcode or unity.

          • Sebastian Weiß

            Trying with Unity 4.6.9. today, I’ll let you know

          • Babybet

            I integrated my entire native project files into the unity imported to xcode project and followed the second half of the tutorial. It works fine now.

          • Sebastian Weiß

            Care to explain? What OS Version are you on, what xcode, what unity? Maybe email me to der.coernel@gnail.com ?

        • Good news, I’ve just downloaded Unity 5 and got it working with Xcode 7.1.

          I’ll try to create a new video tutorial this weekend showing you the process.

          Cheers,

          Frederik

          • Babybet

            Hi thanks. I have some doubts. In my project I am using vuforia in unity as one window and rest of native files in the second. I wanted to pass the name of the recognised reference from vuforia to objective c for some further purposes. I can get the name in unity but how will I access that in objective c? Is it possible that I can access the database values from native in unity?

        • You can check the new video tutorial for Unity 5 & Xcode 7 here http://www.the-nerd.be/2015/11/13/integrate-unity-5-in-a-native-ios-app-with-xcode-7/

          • Babybet

            Thanks for the tutorial. I’m about to check it now.

      • Marco Antonio Navarro Montoya

        Hi, the error persists “ld: library not found for -liPhone-lib
        clang: error: linker command failed with exit code 1 (use -v to see invocation)”. i am using unity 4.6.7f1 and xcode 7.0.1.

  • Guille Espejo

    Hi! Thanks a lot for this tutorial, it’s been extremely useful being one of the few (if not THE only one) that shows the full process of integration and with mostly updated versions of Xcode and Unity.

    However, I’m experiencing the same error as ‘Babybet’, whatever I do I always get the “ld: library not found for -liPhone-libclang: error: linker command failed with exit code 1 (use -v to see invocation)” when using Xcode 7 and Unity 5.

    I’ve cleaned the project, cleaned derived data folder, I’ve deleted and readded libiphone as you do in the tutorial but still no luck.

    Any idea on this one? I’ve noticed that the library being added is called “libiPhone-whatever” but the missing one is called “liPhone-whatever”…
    Any help would be really appreciated!
    Thanks for your time 🙂

    • Hi,

      I haven’t had the chance to test it with Unity 5 yet. As far as I know, we’ll stick to Unity 4 for a little while longer.

      Sorry!

    • Good news, I’ve just downloaded Unity 5 and got it working.
      I’ll try to create a new video tutorial this weekend showing you the process.

      Cheers,
      Frederik

    • hardylr

      Removing libiPhone-whatever from xcode, renaming the file to liPhone-whatever and adding it back again to xcode worked for me

  • Ved Prakash

    Hi ,
    Its very helpful article and very well done but I am not able to find out how it will work for storyboard as our entire app is build in storyboards and it difficult to change this stage .I got impression that you are deleting the existing storyboards and then not adding again.

    • Jorge Avila

      Hi ! same problem.
      Any luck ?
      Thanks

  • Arthur

    Hello everybody,

    Thanks frederik for this very helpful tutorial.

    At the 23d minute, when compiling I have an issue saying that library not found for -lVuforia
    error: linker command failed with exit code 1 (use -v to see invocation)

    I have tried to work on the library search paths and header search paths and also delete libvuforia.a from “link binary with libraries”
    Do you have any idea or any help for me, that would be amazing ?
    Thanks in advance

    • Arthur

      Do you think it is normal that in my Build Phases “Link with binary libraries” I have 22 items instead of you getting 19.
      I have libVuforia.a and libQCARUnityPlayer.a, and my problems are coming from those two. But if I erase them, it get worse in terms errors, I am a little bit lost

  • Rémy Tauziac

    I’m trying to complete this walkthrough with Xcode 6 and Unity 5.

    I’m getting errors (nearly a thousand) at the 26th minute of the video, lots and lots of Undefined symbols for architecture armv7, all are cv:: and std:: missing methods.

    I put back the C++ Standard library to ‘libc++ (LLVM C++ sdt lib with C++11 support)’, and all the std:: error were gone.

    In Unity 5, opencv is embed as a framework, so I have to drag it manually from the Unity project export into my linked frameworks list.

    Now my project compiles, but I have a crash at launch on the Unity DisplayManager. Looking for clues why it happens.

    • TCD

      I had the same issue with the blank camera feed. The issue was that I wasn’t using VuforiaNativeRendererController, it was just using UnityAppController. Try throwing down a breakpoint to check that the Vuforia code is getting executed.

      • Rémy Tauziac

        This solution didn’t fit my needs so I prefered make the project exclusively with the new Unity GUI system. Thanks anyway for the help.

  • Fábio Barreiros

    I’m getting errors in all c++ try catch blocks. It’s says the e.ex is undeclared.
    catch(IL2CppExceptionWrapper& e){
    __last_unhandled_exception = (Exception_t229 *)e.ex;
    goto FINALLY_001a;
    }

  • Kevin

    Dear Frederik,

    Do you have any idea when you might be able to upload a new video in which you show how to do this with Unity 5? Thanks a lot for your time!

  • Pingback: Integrate Unity 5 in a native iOS app with Xcode 7 - the-nerd()

  • Azad Shekmydeen

    Hi, How to kill or quit or unload the unity from iOS App when I clicks a button from native. When I click quit it should quit only unity and not the iOS App. Can you give your views how to achieve it?

  • star

    hi,may i ask how to deal with this problem?

  • Muhammad Sijjeel

    Hi, Its good to go till displaying the Unity view. but when i try to add “UnityAppController.h” in pch file then it does not give me the Classess suggestions. Can you please let me know if i have missed something?

    Regards

  • Sudha Tiwari

    hey.. Can you help me creating a plugin for ios native. My question is : How can I pass a uiview from unity to xcode..?

    Actually I want to show ad to an unity view from xcode.. So for that I need to take a view from unity.

  • 巩昊

    Hello, please use this copy Thank you

  • 巩昊

    excuse Please use this copy thank you

  • Renzo Gamero

    any idea guys?

  • Renzo Gamero

    hello. I made the tutorial again and i have this issue .
    CameraCapture.mm:116:2: Use of undeclared identifier ‘static_assert’; did you mean ‘static_cast’?

  • Jacobo Koenig

    Hi.. After many attempts to compile, I get an error: library not found for -lVuforia. Any idea on how I could be able to fix this?

  • pretentious

    Great tutorial! I’m wondering if this can be integrated with the imessage extension (ios10)
    I couldn’t get it to load because there’s no appdelegate file. do you have any suggestions how I can tackle that?

  • ammad raza

    Hi, how do I go back from unity game to native app

  • Flower Apps

    Hi! thanks for Tutorial.

    I have the Unity- iOS integration and is working. I was wondering if it is possible when I click a button in my Native Swift iOS app get the score label of a game object “MasterScore” that have .js file as script in Unity.

    This is the .js script in Unity
    static var gsocre: int = 0;

    function OnGUI() {

    GUI.Label (10, 10, 100, 20), “Score: ” + gscore;

    }

    The question is how can I do in my swift project to get the gscore

    var myScore = “”

    myScore = “The gscore value fromUnity thats is inside the object “MasterScore””

    Thanks , I hope you can tell me a solution for that question.

  • Rajneesh Kumar

    Hi

    i’m getting error while setup unity 5.6.2f1 project in swift native code. I’m using Xcode 8.3.3

    error : ld: library not found for -lzbar