How To Port an iPhone Application to the iPad (Storyboard) - ios5

I just finished my iPhone app and I want to make it Universal. I've read a few posts already but they're a bit old (2010 or so).
What I got:
Simple iPhone app, recently created (iOS 5 - Storyboard), with three screens.
My app represents a table with three cards that you can flip touching them. The user can input (on the second screen) text to be displayed on the cards.
When I created the project I checked "Universal" so I have two Storyboards. After that nothing else I did had to do with iPad (except for a line on my "contact support" email option where I used UIModalPresentationPageSheet).
What I'd like to accomplish:
Same app on the iPad: my application is so straightforward I don't have any use for split views or details. I just want the same objects and layout but with bigger and better graphics (table, cards, etc).
I like it because it'd make a great introduction-level migration.
I have no idea where to start. When I run the iPad simulator a white screen comes up and that's it.

Well this is done.
As with almost everything, this is pretty easy once you know what to do.
I'd say that for those cases like mine, where the UI doesn't change in more than sizes or (x,y) coordinates the process could be summarized like this:
Replicate every UI element on the iPad Storyboard (copy and paste will do) and adjust position and size as you see fit
Re-wire everything again. Every button, segue (you'll have to add the segue name again too), etc.
Verify within your code every place where your UI is affected (e.g. x,y coordinates), identify whether the app is running on an iPhone or iPad, and divide your code accordingly
If you have any localization on the application you'll have to update the new UI elements on the iPad Storyboard
Select the target for testing on the simulator and try it out
In order to identify in which device the app is running you can use the following:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//I'm running on the iPad
} else {
//I'm running on the iPhone
}
And that's it. Again, in a simple case like mine the reuse of code is absolute (100%), the new code you'll have to add is minimum (basically IF statements where needed), and the UI elements duplication is as easy as copy and paste.
I hope this is useful to someone else and if you have recommendations to improve this they're more than welcomed.

Open the Storyboard file in finder,Copy your iPhone-Storyboard and rename it Main-iPad.storyboard
Inside xCode, right click on the storyboard -> “open as” -> “Source Code”
Search for targetRuntime="iOS.CocoaTouch"and make it targetRuntime="iOS.CocoaTouch.iPad"
Now save everything and reopen Xcode -> the iPad-Storyboard contains the same as the iPhone-file but everyting could be disarranged you have to arrange it by your self.
Finally to get the iPad format also change the code in the MainStoryboard_iPad.storyboard from: to
Then go to your "StroryBoardEx-Info.plist" file,search for "Main nib file base name (iPad)" and make it "Main-iPad.storyboard"

If you just want to reuse your iphone storyboard, just go to your project settings. In TARGETS tab Info, there are rows 'Main storyboard file base name' and 'Main storyboard file base name (iPad)'. Just edit the iPad one to have the same value as the other. In my case I had to edit it as 'Main storyboard file base name (iPad)' with value 'MainStoryboard_iPhone'.

Related

How to reuse UIControl from iPhone xib to iPad xib

I am converting my application into Universal, So I have created iPad xib with ~ipad.xib extension. Now I want to use all the old UIControls used in iPhone.xib in iPad.xib without recreating and connecting, Is there any way to reuse it? I have checked in one SO question he mentioned copied and used it in iPad. How to do it?
First take back up of your application.GO to your app target section and right click there u will get three option like Duplicate, Delete, Project Editor Help....Now Select Duplicate it will show alert like below image. Now select "Duplicate and Transition to iPad".Xcode will generate all xib's for iPad with connections.Copy all xibs of iPad to original application.
just select all controls make copy & paste in new .Xib .

Adding iPad XIB to a View Based Application Template Application in XCode 4

I've created a View Based Application in XCode4; when creating the application I selected iPhone as the Device Family:
The application was created with the following files:
I designed the UI on the TestushViewController.xib file and without adding any code in the Delegate files, the application is uploading immediately to the TestushViewController.xib view and I'm very happy about it.
Now I want to add an iPad xib. How do I do that?
(I knew how to do it in XCode 3, but I used some code in the Delegate file, and now if I try to use the same code it doesn't work because the template default implementation works differently - Apple uses #class TestushViewController and self.window.rootViewController = self.viewController and it goes directly to the iPhone.xib. I don't know how to go around it without changing the entire thing to the way it was done in XCode3)
You'll need to structure your code in a similar way that the Window Template does. The file structure that template uses when the "Universal" option is ticked at creation is:
App Name/
AppNameAppDelegate
iPhone/
AppNameAppDelegate_iPhone
MainWindow_iPhone.xib
iPad/
AppNameAppDelegate_iPad
MainWindow_iPad.xib
The iPhone and iPad AppDelegates are simply subclasses of the AppNameAppDelegate
#interface YourAppNameAppDelegate_iPhone : YourAppNameAppDelegate {}
In your target summary you can set what .xib file is initially loaded for each device. It is called the "Main Interface" and has a pulldown menu.
Quite frankly, if you're wanting to do a universal app (iPhone + iPad) it's probably easier just to start with the Window Template and add in your view controllers instead of starting with the View template and trying to change it up.

NSInternalInconsistencyException Could not load nib ind bundle

I am developing an application for the iPad. The application has following details:
Base SDK: 4.2
Deployment Target: 3.2
The application is a game application and it has got 10 rounds.
In each round I am loading 6 controllers and after the completion of each round again the same cycle starts.
The application works fine till 4 rounds but at the end of 4th round it crashes given following error:
"NSInternalInconsistencyException Could not load nib ind bundle:"
I have checked for everything solution like checking the nib file name, checking the nib file path. Nib file name and nib file path both are correct and targets are also correct but still it crashes.
Any help for this will be appreciated.
Thanks,
Shyam
Right click your nib file in xcode and make sure its type is 'file.xib'.
I had this problem too, in my case the cause was that my project had no localization to italian but the app was running under "it" settings.
The simulator has English as regional setting by default, everything was ok on it while the actual device had italian settings, so the app crashes immediately when attempting to load the RootViewController, because it was looking for an italian version of it.
In XCode I added an italian localized version to the RootViewController (now I see two entries under it, one for english created by default and italian). Note that you don't need to do the real translations in the view, it's enough that you create it and leave as default. Xcode copies all labels and text from the original view, you just leave as is for the moment.
You'll have to do this for each view controller in your project. Refer to Apple docs, for explanations on internationalization and localization here.
As a workaround, some people might prefer to change the device regional settings to English while performing tests...

How to Show a GPL licence in iphone application bundle

i am making an app for iphone and for that i am using certain free libraries.My problem is that i want to show their complete license of nearly 4-5 pages in my application bundle so that a user can open settings in iphone and see that licensing page at one time but i am unable to do it.I have read these Specifiers for making an application bundle .
PSGroupSpecifier
PSTitleValueSpecifier
PSTextFieldSpecifier
PSSliderSpecifier
PSToggleSwitchSpecifier
PSMultiValueSpecifier
PSChildPaneSpecifier
but i want to show a page full of text like Settings->General->About->Leagl
just like in iphone through PSChildPaneSpecifier .Please help me how to do this>???
Thanks
You can create the same effect as used by Apple's iWorks apps for the license > section of the settings, without using any custom preference controller. Note this works for iOS 5 on the iPad, I have not tried it elsewhere. Use a PSChildPaneSpecifier for the initial control in the root plist. This points to the name of another plist file which will be the displayed child pane. You do not add .plist to the name within the root.plist file, it is implied. This plist file must be within the settings bundle. Next, use PSGroupSpecifiers in the child pane as the controls. For each paragraph use another PSGroupSpecifier - so the thing will scroll. Only use the Title section of the PSGroupSpecifier. The next gotcha that I found, was that by putting the strings in the plist file, the text was clipped in portrait orientation, so a placeholder string needs to go in the plist file and a StringTable used to point to a strings file. Text read from the strings file is properly kerned and displays without clipping.
The iPhone's "Legal" page is a custom preference controller which you can't use (not even with undocumented methods – you need to write a preference bundle in system locations which AppStore apps can't reach at all).
If you'd like to display the license, show it in the app.
I think you are going to need to use something like a UITextView, just make it non-editable. You can make in unobtrusive in your app but I think that is the only way to have 4-5 pages.
I don't think there is a nice way of displaying this in the preferences bundle. Personally I would either provide a series of url links or bring the preferences into the app itself. There is a good framework on github here that you may be able to modify.

Is it possible to change the app icon programmatically?

I want to make two different app icons, and programmatically switch betweem then. When the user quits the app without finishing an workflow-process, then I want to switch to an icon that will indicate that there's something undone when launching the app. Well, just theoretically, just for testing.
I think that the icon file is just a normal file as any other, so if I would just rename it programmatically and then give another icon file the name of the icon file that's named the Info.plist, then the app should show up with another icon, right? Would that be possible? Or do I have no access to that file for renaming it?
icon file stored in "application bundle" folder.
And your application has read-only rights to this folder
There is no oficial way to change/rename thees files.
You can add integer badge to youy icon
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:666]
But it is not official method.
It sounds like a good idea, and I would definitely give it a try, but I get the feeling this isn't possible.
I believe the app icons get stored in another file structure global to the iPhone. I say this because after I installed 3.0 beta 5, I saw a bug where the app icon disappeared from an app I developed. Then after installing two new apps from the app store, the new app's icon appeared on my app, and the 2nd new app's icon appeared on both new apps. Essentially the new app icons shifted to fill in for the missing app icon.
Removing and re-adding the apps, then rebooting the phone, restored the icons properly.
I don't know for a fact how the app icons are managed and stored on the phone, of course, but it would fit to say they are stored in some sort of cached list that gets rebuilt occasionally, perhaps after a reboot. That would mean even if you could change the icon from within your app, it would take more effort to see the effects on the phone.