Existing ios project making compatible with iPhone 5 [duplicate] - iphone

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to detect iPhone 5 (widescreen devices)?
I already have a project which is running properly on iPhone 4 and iPad. Now I want to make that project compatible with iPhone 5 (4 inches).
I have tried using the "Use Auto Layout" but its not working.
My Xcode version is Version 4.5 (4G182).
I have searched over the internet but couldn't find any clue.
If anyone has already resolved this issue then please guide me.

put a Default Image for iPhone 5 in the project called Default-568h#2x.png.
After that the iPhone 5 simulator launched my App fullscreen.
Depending on your Layout you maybe don't need auto layout. I could solve all layout problems with the autoresizing settings in IB. In the end it was simple. I had four kinds of problems:
View Controllers that should be fullscreen
Elements with fixed distance to the top
Elements with fixed distance to the bottom
Elements with dynamic distance to top/ bottom that should be scaled with the size of the container
I preffered this way in my existing project. In the next project I will check out the auto layout functionality.
Best,
Benjamin

I won't recommend creating a separate xib file, This is what I do:
1. Adding 4-inch launch screen - it's a must if you want to use all iPhone 5 screen, There is no other settings for that.
2. If you are using a xib file just open it with interface builder and select every view button etc. and set it to be dynamically placed (using the ruler tab). Pay attention to set windows also to stretch up.
3. If you code your view check that you are dynamically set the places and sizes.
Pay attention that "Auto Layout" isn't backwards compatible so it won't run on versions of iOS before iOS6 (it simply crash)! It is probably useful if you are starting from scratch but for old apps that isn't so good.

Have you tried adding a new launch image named Default-568h#2x.png to your project?

One of the possible solutions (probably not the best one) is to load different .xib files depending on screen size. This way you can stil save compatibility with previous iOS versions (<6.0).
You can add a category which selects proper .xib file, instead of initWithNibName:
#implementation UIViewController (iPhone5Support)
-(id) initAutomaticallyWithNibName:(NSString *)nibNameOrNil orIOS6NibName:(NSString*) IOS6NibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
BOOL isiPhone5 = CGSizeEqualToSize([[UIScreen mainScreen] preferredMode].size,CGSizeMake(640, 1136));
if (isiPhone5==NO) {
self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
} else {
self = [self initWithNibName:IOS6NibNameOrNil bundle:nibBundleOrNil];
if (self==nil) { NSLog(#" initAutomaticallyWithNibName ERROR - nil for io6 nib name"); }
}
return self;
}
#end
Use it like that:
UIViewController *controller = [[UIViewController alloc] initAutomaticallyWithNibName:#"UIViewControllerXibName" orIOS6NibName:#"UIViewControllerXibName_4inch" bundle:nil];
(don't forget to create 2 xib files for the same controller)

Related

Converting an iphone application into an iPad , iOS?

I currently have an iOS iPhone application.
What i want to do , is make it universal so that i can target the iPad too.
What i did , was go to the target and change the iOS application target , from iPhone to universal.
Now when i run the application on my iPad , it automatically resizes all the views for the iPad.
However there are some views , with background pictures that dont look so good , cause i need to use higher resolution pictures or in general i should change some things in the iPad version.
Where are the iPad .nib files??? I mean , i only see the iPhone ones. When i run it on my iphone , these files are used. When i run it on my iPad everything is resized correctly , but where the hell are these .nib files?
The tutorials (pretty old) that i read , suggested that when you target the iPad too , new .nib files should be created exact copies for the ipad. Why i dont see these files?
You can have iOS automatically load the right xib based on the extension, akin to how Retina graphics work. If your xib is named Awesome, and you want to convert it into having an iPhone and an iPad version (instead of being shared, rename it such that:
iPhone version:
Awesome~iphone
iPad version:
Awesome~ipad
Then, when you tell iOS to load Awesome, it'll pick which one to load based on the current platform automagically. No need for if statements in your code! You can still if you want, but it's not required.
Note: You might need to perform a clean after the rename! Sometimes some files stick around in the build when renamed.
You will just need to make new .xib files and set them to the same class and you can init that viewController with a condition:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
yourVC = [[YourViewController alloc] initWithNibName:"YourViewController_ipad" andBundle:nil];
}
else
{
yourVC = [[YourViewController alloc] initWithNibName:"YourViewController" andBundle:nil];
}
Whenever possible you should try to use the same .xib but in a lot of cases it isn't possible to do that and look good so you just make a second. Xcode won't do it automatically for you.
Let's say that you have a class. We'll call it Two.
Here are the current files that make up the Two class.
Two.h
Two.m
Two.xib
Two.xib contains a UIView sized for the iPhone. In order to make a view sized for the iPad, you should create a new XIB file (name it Two_iPad.xib), connect the XIB to Two, resize the UIView in Two_iPad.xib for the iPad, and design accordingly.
When you are creating a new instance of Two, do the following.
Two *two;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//they are using an iPad
two = [[Two alloc] initWithNibName:#"Two_iPad" bundle:nil];
} else {
//they are using an iPhone/iPod Touch
two = [[Two alloc] initWithNibName:#"Two" bundle:nil];
}
You are creating a new instance of Two; however, you are checking which device the user has, and using the corresponding XIB file.

Making universal build for iphone application with xcode 4.51

I had an old project which uses XIB for each UIViewControler.That was intended for I Phone but now I want to make that project with universal build that is for Iphone as wall as IPad also.The problem is that when I changed the build type to Universal and used coding like
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
// ipad coordinates
}
else
{
//iphone coordinates
}
this the display is correct on iphone and ipad but on ipad the buttons are not taking click event on entire button but only on a small portion of button.Though I am not loading Nib but it is taking crated iphone xib file internally and I think thats why it's button behavior is not in accordance to ipad view. I am confused that what I should do?How to make copy of XIB for Ipad and load them depending upon device.It is to mention here that I am not loading any nib from my code but It is being called internally. Please help
For universal app you can make 2 xib
1 - > yourView_iPhone
2 - > yourView_iPad
And load each xib according yo your idiom
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
yourView *obj = [[yourView alloc]initWithNibName:#"yourView_iPad " bundle:nil];
// ipad coordinates
}
else
{
yourView *obj = [[yourView alloc]initWithNibName:#"yourView_iPhone " bundle:nil];
//iphone coordinates
}

iOS - Converting iPhone Build to iPad

I have a application that I built that was to be build as an iPhone-only application.
Now, I am told that the application has to be made universal now. I will have to make it iPad compatible too (in portrait-only mode). I have been looking for my options right now as the XIBs in this project are heavily loaded with objects so programatically assigning co-ordinates will be a pain.
I am looking for the best, and the quickest approach I should take to make this iPhone app into iPad-compatible app as well.
PS: There is no mainwindow.xib file as the application was built with XCode 4.3 which doesn't create the MainWindow.xib file.
Thank you in advance.
EDIT: I have made duplicate XIBs for iPad for all the XIBs. Now, I am trying to use the naming convention which tells me to change the filename suffix to MyiPadXIB~ipad.xib and when the app is run on iPad, it will automatically take that XIB. This doesn't seem to be happening.
When I open the application in iPad, only a small window appears (the window that appears when iPhone-only app is run on an iPad).
Any solution to this?
I followed a very easy approach where I would just create duplicate XIBs of all the XIBs by doing Build settings > target (iPhone)> right click and choose duplicate.
I would then change the name of the duplicate xibs in this format: "iPhone XIB name"~ipad.xib.
The system would then automatically pick up the XIB according to the device used.
From what I know (there may be a quicker/better approach that i dont know of)
You would create seperate xib files for the ipad
when you init your view controller you check to see what device you are on like so
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.serverSettingsViewController = [[ServerSettingsViewController alloc] initWithNibName:#"ServerSettingsViewController_iPhone" bundle:nil];
self.motionJpegViewController = [[MotionJpegViewController alloc] initWithNibName:#"MotionJpegViewController_iPhone" bundle:nil];
} else {
self.serverSettingsViewController = [[ServerSettingsViewController alloc] initWithNibName:#"ServerSettingsViewController_iPad" bundle:nil];
self.motionJpegViewController = [[MotionJpegViewController alloc] initWithNibName:#"MotionJpegViewController_iPad" bundle:nil];
}
And load you iphone or ipad xib file (FYI make sure the xib views are large enough for the ipad)

2 XIB and 1 viewcontroller but functions don't work in the ipad XIB

I believe that I did everything necessary to change my app for ipad (was for iphone at start). I can toggle the build status to either iphone (only), ipad (only) or iphone/ipad - and the app launches either in ipad or iphone simulator. I can do that forth and back at will.
I added the idiom to check for ipad and basically for one of my xib, instead of using the string of my xib to create the controller, I use the one for the ipad. So it is a new xib for ipad with all same graphical objects ( enlarged ;-) ) . I added the callbacks to function correctly with IB.
I can see everything fine and arrive on my new ipad view BUT when I click on one of my buttons... nothing happened like if my callbacks don't work. It is very surprising and actually I have no idea where to look as I compared most of the parameters between my iphone and ipad view and they are identical as far as I can see.
It must be something damn obvious so if one of you had the same issue and it was a very simple answer ... I guess that would be what I missed!
Thanks for your help in advance
Cheers,
geebee
EDIT1: Some code as requested
at start I have that to decide either way:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
examTFVC_NIB=#"ExamTFViewController-iPad";
}
else
{
examTFVC_NIB=#"ExamTFViewController";
}
Then to go to the right view:
ExamTFViewController *examTFViewController = [[ExamTFViewController alloc]
initWithNibName:globals.examTFVC_NIB bundle:nil];
But I have no problem loading the correct XIB. The issue is really the callback functions not being called...
Thanks for the help.
EDIT2:
I also realised that calling the extension of the xib xxx~ipad allows to avoid the example code above. And it works - but still no function can be called.
EDIT3:
IMPORTANT FINDING: if I move my buttons higher and on the left of the screen: they work! So it seems that the functions are called if the event are in the region of an iphone screen although I am on an ipad screen. I guess know it would be more obvious to find the issue! thanks for any help – geebee just now
ANSWER
iPad touch detected only in 320x480 region
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// to correct region size
CGRect rect = [[UIScreen mainScreen] bounds];
[window setFrame:rect];
// now, display your app
[window addSubview:rootController.view];
[window makeKeyAndVisible];
}
** OR OTHER SOLUTION **
Check the full screen at launch checkbox - only present in the ipad xib MainWindow
finally solved - with 2 methods - programmatically or via IB - in the edited section of the post.

Adding iPad XIB/VIEW to a "View Based Application" in iOS 4

I've created a View Based Application in XCode4 and trying to do the code and UI design according to the way Apple have intended it to be.
So I designed the UI in the AppNameViewController.xib and it works fine; now I want to enable it as a UNIVERSAL application that runs on iPad as well. I changed the App-Target>>Summary>>Devices from iPhone to Universal and miraculously XCode had automatically created MainWindow-iPad.xib (Apple, very nice...), but since I designed the application first screen on the AppNameViewController.xib and not on the MainWindow.xib when I run the app on iPad Simulator I get this ugly screen where my UI objects size and location is distorted (their size is still set for iPhone so they are all crumbled on the left-top corner of the screen).
In my previous app I used the code appearing below to distinct between the AppNameViewControllerForIPHONE.xib and the AppNameViewControllerForIPAD.xib; It was done from the AppDelegate.m file, but in the new XCode View Based Application template the AppDelegate doesn't go through initWithNibName method at all.
Code I used on XCode 3 that cannot be used on XCode 4:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
viewController = [[AppViewController alloc] initWithNibName:#"AppViewControllerIPAD" bundle:[NSBundle mainBundle]];
}
else {
viewController = [[AppViewController alloc] initWithNibName:#"AppViewControllerIPHONE" bundle:[NSBundle mainBundle]];
}
Long question... still, anyone had any idea how it should be done here? Where should I design the iPad UI or is there a way to easily transform the iPhone xib to an iPad one?
You have to follow the new naming scheme (idiom in Apple-speak) specified for Universal Applications for the NSMainNibFile key in your info.plist. For example, if you set your NSMainNibFile to be "MainWindow-iPhone", the xib for ipad would be "MainWindow-iPad".
The same naming convention should hold for the views in a view based application (I can't test right now, installing new xcode).