Deploying for iPhone from Unity3D can be a little bit tricky, especially when customised code or 3rd party libraries are part of the project. So I decided to publish my own little check list and some hopefully useful information. In general I recommend the newest Unity3D version you can get (3.4 at time of writing) because there were some problems in Unity3D 3.3 leading to a bunch of errors and warnings.
- Start
- First Steps in XCode
- Integrating The Library Files in XCode
- Adjusting The Code in AppController.mm
- Finished
My environment for getting the app up and running:
- Unity3D 3.4
- XCode 4.02
- iOS 4.3.3
- Some 3rd Party static library. In my case it is libm3SysLib.a and its header file m3SysLib.h. Put your library and header file at the places mentioning m3SysLib
- target iOS version 4.3
- target device iPhone 4 / iPod Touch 4th generation
First of all you have to check your build settings (File / Build Settings, button Player Settings):

Before 3.4 the target platform for armv7 was called “armv7 iPad only” which is pretty confusing as iPhone 4 was supported very well. SDK Version should be “iOS latest” to avoid manual configuration after XCode updates.
Pressing “Build And Run” popsΒ up a file chooser dialog for selecting output folder where to generate all XCode related stuff. Note that on subsequent builds to the same folder, Unity3D asks you if the generation should replace or append. Because we are going to make a couple of changes in the project file you should always press “Replace” later on, otherwise you have to repeat all your steps. Like always: backups are a pretty good thing π
Now in XCode we have to check the project settings first:

We use armv7 architecture only because of the static library to include. If you need to run your app in simulator you have to provide an i386 version of your lib as well. Thus configuration gets far more complicated. Note the “Latest iOS” entry which should be set automatically by Unity3D. If not, set it manually.
OK, let’s try our very first CMD+B (build) without the library. I have got two warnings (Semantic Issues regarding kScreenOrientation and an incompatible pointer type UIViewEAGLView) that can be ignored. If your build fails or if XCode hangs during the last build phase, check the scheme (Product / Edit Scheme…). Sometimes the simulator is set as target by default after the very first Unity3D export, but we want to deploy the app on our iPhone:

Integrating The Library Files in XCode
Before we use a 3rd party library in XCode we need to
- Tell XCode where to find library
- Specify the location of the header files
- Optionally include a DefaultSettings.bundle
The library file must be linked to the app in XCode. This is done in project settings. Just select “Unity-iPhone” in the “Targets” section at the left and go to the “Build Phases” tab. The last expandable row shows the libraries to link with and new libraries can be added by clicking the “+” sign and choosing “Add Other…”. Note that your library might depend on some frameworks in my case for example CoreMotion.framework. These have to be added as well. After adding the library file itsef (in my case libm3SysLib.a) from file system and dependent frameworks you should have something similar to:

Header file including takes place in the “Build Settings” tab of the project. Just add the location in “User Header Search Paths”. Hint: Use the search field to filter:

If your library relies on a default settings bundle, just copy it from wherever it is supplied to the project root.
Adjusting The Code in AppController.mm
In order to handle app life cycle properly we need to edit some code in AppController which is the UIApplicationDelegate of our app. Following places will typically need to be adjusted:
- Header file include section, take your header file instead of m3SysLib.h:
#import “m3SysLib.h” - – (void) registerAccelerometer
If you don’t need it or like in my case use more sophisticated sensor handling, type return; in the first line to avoid unnecessary sensor usage. - – (void) Repaint
I commented out the whole if block if (kAccelerometerFrequency > 1e-6 … for the same reason - – (void) applicationDidFinishLaunching:(UIApplication*)application
Here we do our library initialisation stuff - – (void) applicationDidBecomeActive:(UIApplication*)application
Called every time the app becomes active - – (void) applicationWillResignActive:(UIApplication*)application
Called every time the app becomes inactive i.e. goes to background - – (void) applicationWillTerminate:(UIApplication*)application
Optionally for old iPhone 3 systems that do not support multi-tasking - Other events you want to react on
We are hopefully done and everything is up and running. Using our library from inside Unity3D would go beyond scope of this blog entry. I recommend Clever Martian’s Blog – An Experiment with iPhone Native UI and Unity 3 Pro. It helped me a lot and his downloadable example project was easy to set up.
If you liked this posting don’t hesitate to push the Like, +1 or Twitter button, or you may leave a comment below (no registration required).
The correct link is https://web.archive.org/web/20121105041631/clevermartian.com/blog
Thanks π I updated the link
Hey, the given description is to the point and very clear so it is useful for the beginner also. And expert can get direct help from here. Keep sharing π
That’s just spam; he wants his URL on your page to help his page rank. π
This is an excellent blog. I got many unknown information from this post.
well written, find your style of writing is very rich. Written in a very good, hope you can continue to try hard, to write better!
Hey, it’s really good post. Thanks for sharing.
This post was fantastic! You made some great points. Actually I was not aware about that. But I found here many beautiful info in your post.
I totally appreciate you for sharing the worthy information. Liked reading and knowing about it. Thanks for sharing your efforts!
Thank you π
Hi..I really liked all the stuff provided by you. Your efforts are really admirable. Thanks a lot for sharing.
Hi,
Useful post. Thanks very much. I also found this to be quite useful guide on getting native functionality in OSX by creating a new native plugin http://www.reigndesign.com/blog/unity-native-plugins-os-x/#more-2824
Hey,
Great post there. Very useful indeed.
Thanks for the share. i
Thanks. I will write an article about our “more sophisticated sensor handling” when we are going to launch our game in early 2012. It deals with getting more information out of the gyroscope and accelerometer sensor data to track more complex motions.
Interesting post, I’ve never really tried integrating native stuff in unity, but always nice to be up to date on the possibilities.
Btw. any chance you could elaborate on your “more sophisticated sensor handling”? That sounds interesting and is beyond my imagination.
Thanks it’s a very good tutorial! Helped me get my stuff runing
This is a nice Post.I want to Android application.