Login

Creating a Universal iOS App Tutorial

Just when I thought I had a somewhat decent grasp on developing and deploying iOS apps Apple came out with the iPad and threw a whole new element in the mix when it comes to developing.  Thankfully, the iPad will allow iPhone apps to run on the device, but the user experience is definitely sub-par.  So what is the best approach to providing an native iPhone app and a native iPad app?  The first option is to duplicate your existing iPhone app code base and modify all your views and some of the controllers to take advantage of the features in the 3.2 SDK.  The problem with that is the massive DUPLICATION of code and to be honest it seems quite lazy.  I have seen lots of examples where developers use the idiom check for which device is being used, as well as, runtime checks for selectors in order to leverage the correct methods/classes for the given device.  While this is certainly a better approach then having two separate code bases with 90% of the same code you now have code that is sprinkled/littered with if/else checks.  Unfortunately, you are once again stuck with code that will be maintainable for long.  After reading the chapter on universal apps from the upcoming book from Pragmatic Programmers, iPad Programming, I found a much better design pattern of splitting out the app into Shared, iPhone and iPad resources, classes and delegates.

As a side note, due to the ever exponential growth of iOS device popularity developers are not going to have the bonus of just jumping straight into writing an app like we did when there was just the iPhone.  A lot more thought needs to be given to design patterns (especially regards to the quality of your MVC) and application flow.

In order to make life a little easier on myself since a few universal apps are coming in my near future I decided to create a basic "template" for a universal app.

Features
  • Compiled for 3.2 and 4.0
  • Utilizes navigation controller based app for iPhone device and SplitViewController for iPad
  • Shared "model" class and controller classes
  • Separate resources (classes/xibs) for the different devices

Comments and improvements are ALWAYS welcome.  One improvement that I know I want to make is having the "detail" controller from the SplitViewController to be a UINavigationController.

22 responses

Ladd Usher said
Hi Cory,

Very nice succinct example.

Thank you!!!

Cory D. Wiles said
Thanks Ladd.

If you have any comments or questions about the project please let me know.

jedjak said
That is a great example, it's perfect as a starting point for a Universal App. Apple should've released something like this in the first place. Thank you for posting.
Cory D. Wiles said
Thank for the compliment. I am glad that it helped you. If you have any features or fixes that you would like to see please let me know.
Ayon said
Great Tutorial. Thanks for this kind of post. Would like to see more from you. :)
Cory D. Wiles said
Ayon,

Thank you!  if you have any future tutorials or suggestions to the Universal App that want to see added then please let me know.
Jesse Head said
Good stuff mate! This will help me out a whole heap.
Rain said
Hi,

I just want to know why should we make it like share and create different files for iphone and ipad.

For example i have sign up page and in that i have one function in which i have little bit different code based on ipad and iphone.

So think like i have around 100 lines of code in that function and i want to change only 2 line based on iphone and ipad device.

So in that case shouldn't we go with conditional code instead of write duplicate code in 2 different files?

Cory D. Wiles said
Rain

In your situation you are better off having one set of files and doing runtime checks. My universal template is more for larger apps that have vastly different UI. Think twitter clients for iPhone and iPad. 

If you have any suggestions to make the template better please let me know. 

Thanks,
Cory 

Sent from my iPad

Edgard Matos said
Very! Very Great!!! Thanks friend!
Edgard Matos said
One question.. Why in some files names do you use "Pad" , "Phone" and in another, you use "iPad" and "iPhone"? Thanks!
ali raza said
this is great. thank you so much!
A said
Hey,
great resource.
One quick question: Where do you determine if its iPhone or iPad?
Cory D. Wiles said
There is a check at runtime for which nib to load based upon the device that the app is running on which is set in the info.plist.


Jacob Monday said
Great job Cory, very helpful!
GodHasAmnesia said
Hey- thanks for the great template! I removed a bunch of redundant Foundation.h and UIKit.h imports in some of the headers... FYI

I especially like the beauty of subclassing the view controllers. Very well done!

You have my vote to go independent iOS pro! Don't go be a slave for another corporation! Let me know if you need some small side projects to work on... I'm sure there are others like me who have lots of app ideas but not enough time to work on them all.

iPhone newbie said
This is awesome! thanks :)
Praveensss said
Nice post. Thanks!
Cory D. Wiles said
Anytime. If you have any suggestions or questions please let me know
MWorks said
Hi Cory!! Nice post!! But, I'm a Unity 3D programmer... do you have any suggestions for me? Can you help me developing an Universal App?? We can work together to make it possible. You have my mail... Regards!!
hbastan said
Hi Sir,

for universal apps , how should be the images, do i need to include , image for iphone, iphone-retina , ipad and ipad retina ??

Cory D. Wiles said
Yes. 

Sent from my iPhone