1

I am developing an application, in it as the client requirements, few views are compatible for only iPhone 4 devices and other views are compatible for both like iPhone 4,5 /iPad. So is it possible in single build?

I know it is not possible but I want your suggestion for the same. If you have any link related to that then please share with me.

LuisEspinoza
  • 8,508
  • 6
  • 35
  • 57
Apple
  • 736
  • 1
  • 6
  • 24
  • 1
    how can i give you the code ? i just want to know that in my application there multiple XIBs and few are for iphone only and others are for universal(iphone/ipad), and the problem is that in ipad , i have to call iphone xib in few scenarios and it must display in the middle of the ipad screen. so is it possible and this type of application is valid for apple ? – Apple May 28 '13 at 13:12

2 Answers2

7

Yes, it is possible to have different views for iPhone 3.5", iPhone 4" and iPad. Also, you can implement different features in every different device. However, iOS User Interface Guidelines recommends that you provide same functionality across different devices.

Preserve the primary functionality of your app, regardless of the device it runs on. Even though one version might offer a more in-depth or interactive presentation of the task than the other, it’s important to avoid making users feel that they’re choosing between two entirely different apps.

In practice, you can programmatically write a bifurcation to build (programmatically) a view using this macros:

#define isIpad() \
([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] && \
[[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPad)

#define isWidescreen ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 )<DBL_EPSILON )
#define isIphone ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPhone" ] )
#define isIpod   ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPod touch" ] )
#define isIphone5 ( isIphone && isWidescreen )

Also, you can create different xib files for every different devices, using the bifurcation and UIViewController message: - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil, to load the correct file.

Finally, you can use modifiers in the xib filenames to load different resources between iphone and ipad. For example: You have FirstViewController.xib for your iPad UI; you can create a FirstViewController~iphone.xib that will be loaded automatically by iOS if the device is an iPhone (instead of FirstViewController.xib). You can check this answer for more information about this subject.

EDIT

In the case that you have already "iPhone only xib files" and you want to run those on iPad, you should consider to copy each of those files, and convert the copies to iPad target as this or this answers explains . Then, you can re-name this copies ending with "~ipad.xib", that should solve your problem, however, this views will need a layout revision.

Community
  • 1
  • 1
LuisEspinoza
  • 8,508
  • 6
  • 35
  • 57
  • hello luis, thanks for your reply but my problem is that in my applications there are few xibs are only for iphone 4 and few are universal so how can i display those iphone 4 xib in ipad in middle of the screen ? – Apple May 28 '13 at 06:22
  • hello luis, i dont want to create new xib for ipad, i just want to show iphone xib in ipad at the middle of the screen. currently in my app it displays at the left most corner in the ipad screen. so what is the solutions for that ? – Apple May 29 '13 at 07:42
  • 1
    Well, I don't know any option that allows you to load and display an iPhone only nib like an iPad does with the iPhone only apps. The options that I wrote in my answer are all the ways that I have used for managing different views for iPhone and iPad in a single bundle. – LuisEspinoza May 29 '13 at 17:21
1

just decide this by code. if a view shall be available for iPhone, call it, and if not just let it be. to distinguish between iPhone and iPad just use

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        // iPad
    else if([[UIScreen mainScreen] bounds].size.height == 568)
    {
        // iPhone retina 4 (iPhone 5)
    }else
        // Older iPhones
geo
  • 1,781
  • 1
  • 18
  • 30