Handling different xib files for a lite and full version - iphone

I have a bunch of xib files that I use in my app's full version. In the lite version I want to be able to load some xibs that have less features, thus making it a lite version. All my viewControllers are hooked up in IB, and are referenced by both targets at the moment.
What's the best way to hide functionality beyond simply disabling it? I figured that having an entirely different xib file would be easiest, am I wrong?
Edit:
To clarify, I'm trying to figure out how to load a different nib for a view controller depending on the version. I believe it has something to do with initWithNib.

Use targets, you can exclude/include files per target.
Create a target for lite, which does not include some parts that the full app wil, like load a NIB which has les functionality than the full version.
You can even use the same names for code files (.m) and NIB and include/exclude via the target property.
This will only work if you have a lite and full version in the app store.
If you want a in app purchase then you will need to do what #Jack Humphries suggests.

Yes, you are right, having different XIBs in my opinion would be easier. So, the full and lite versions are in the same app with an in app purchase? I would have a generic home page, and then use NSUserDefaults to link to different pages. For example, here is the code for a button:
-(IBAction)gotogame {
if ([[NSUserDefaults standardUserDefaults] boolForKey"#Purchased"] == YES) {
//go to the entire game XIB
}
else {
//go to the lite game
}
Here is how you set NSUserDefaults:
[[NSUserDefaults standardUserDefaults] setBool:YES forKey"#Purchased"];
Additionally, if you want everything in the same view, use NSUserDefaults, and if the Purchased key is equal to yes, then do this:
[litePicture setHidden:YES];
[fullPicture setHidden:NO];
And vice versa. Let me know if you have any questions!

Related

Lite version of iOS app with changes in scene (storyboard)

I want to create a lite version of my app. When I searched on google, almost all the solutions mentioned to create a duplicate target and set necessary flags (to differentiate between full and lite version).
Now I did the necessary things but in my lite app I want some controls in one scene to be disabled. So how do I do it in the design mode?
With the flag sets I can differentiate between full and lite app while Runtime. But can I make the changes to a scene only for lite app in Design Time?
Or for every scene load, I'll have to check the flag and then do the disable/enable code in runtime.
What are my options? Please help.
I think the most manageable way is in your code. One example:
- (void)viewDidLoad {
[super viewDidLoad];
if (kIsLiteVersion) {
[someObject setEnabled:NO];
}
}
Or, perhaps you'd do this in init in some cases (maybe you want to not create certain objects in the lite version). Or, maybe use the condition to determine which storyboard view controller to push in some cases, and have some for the lite version.

How to eliminate Storyboard

I have an iPhone app in the store that I used xCode 4.2 and Storyboards to create. I now wish for iOS 4.3, and prior, users to be able to use the app... they currently cannot due to the storyboard.
How do I proceed to eliminate the storyboard to gain a wider audience?
Thanks.
There is no easy way to do this, unfortunately. What I would suggest is to manually copy the elements of each segue in your storyboard and paste them each one at a time to a newly created nib file...
Also, dont forget if you go the multiple nibs way, you'll need to edit a bit your AppDelegate and create a MainWindow.nib file. Create a new project using nib files to have a perfect exemple of what to do!

iOS Universal App question

I have submitted my iPad app to apple and got approved. Now, i want to add iPhone support to the App.
My question no.1 is:
Q1. is it possible to make the app universal at this moment after submission?
If yes, i have question no.2
Q2. my iPhone app is exactly the same as the the iPad but only a few views are in different look due to the customization in screen size. What should I do in XCode to specify which class that iPhone/iPad is using respectively? I can build them smoothly when i separated them into 2 projects.
Thank you.
You can modify the same application and add support of other device. you need to resubmit application again.
From with in your code you can detect on which type of device it is executing and based on that you can load appropriate XiB file for each view controller.
Yes.It's easy. you have to create Universal app
File--->newproject-->Windowsbasedapplication
and then you select Product type Universal You have a separate view for iphone as well as
ipad
You can identify device using this
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// iPad stuff
}
else {
// iPhone/iPod stuff
}
Most of the UI stuff can be redone just with autosizing parameters, but some don't.
Also for specific classes that do not exist in iPhone/iPod (like UISplitViewController) you can use NSClassFromString, which will return the object class or nil if cannot be loaded.
Q1: Yes, just convert your project to universal and submit it with the same id.
Q2: Fairly easy, conver your project into universal by following the steps here (http://useyourloaf.com/blog/2010/4/7/converting-to-a-universal-app-part-i.html) . The basic idea is to extract your business logic from controllers and use different controller for iPhone and iPad. Don't try to implement it with code block like that
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// ipad goes here
}
else
{
// other
}
note:
If you google it, you will find this link, don't use it, it is outdated -- http://iphonedevelopment.blogspot.com/2010/04/converting-iphone-apps-to-universal.html

Trouble with loading a separate XIB for iPad or iPhone

Im having trouble figuring out how to load a separate XIB for iPad or for iPhone in a Universal app.
Its easy enough to convert the Xcode project to Universal and have separate Main view interfaces.
My problem is the secondary view and getting it to have separate interfaces for both iPad and iPhone.
Please offer any help you can give as I have been working on this issue for days without success. Thanks in advance!
I know that #indragie's answer is a very common one, but it's a common misunderstanding that will cause you a lot more work than you actually need to do.
As long as you name the xib files a certain way, they will be automatically selected for either iPhone or iPad. Check out my answer to this same problem on another post:
iOS: Using device modifiers for loading xib files?
Just add a file named MainView~ipad.xib makes it load this one i.s.o. MainView.xib when running on a iPad..
You can use UI_USER_INTERFACE_IDIOM() to check whether the application is running on an iPad or an iPhone/iPod touch:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// Running on iPad
} else {
// Running on iPhone or iPod touch
}
For more information on loading NIB files, read Apple's Resource Programming Guide on Nib Files. You may want to specifically check out the Loading Nib Files Programmatically section which shows how to programatiically load a NIB from within your code using NSBundle. You can then use this in conjunction with the above code to correctly load the proper NIB depending on which device you're runining on.

Make iPad app a Universal app

I have an iPad app that I would like to make Universal, however this seems alarmingly difficult. I've changed things around so that I support both builds, but when building, I get lots of errors about using UIPopOvers. Here're my questions:
Why does UI_USER_INTERFACE_IDIOM() not compile or register on 3.1.3?
Can I conditionally have variables in a class definition based on UI_USER_INTERFACE_IDIOM()?
If not, should I make two different view controllers?
Thanks!
Why does UI_USER_INTERFACE_IDIOM() not
compile or register on 3.1.3?
The UI_USER_INTERFACE_IDIOM macro is only available starting with 3.2. Same restrictions for the userInterfaceIdiom property of UIDevice. This means that you can only get universal application starting with SDK 3.2.
Can I conditionally have variables in
a class definition based on
UI_USER_INTERFACE_IDIOM()?
No. The UI_USER_INTERFACE_IDIOM macro is only a runtime shortcut to get the current UI idiom of the device.
If not, should I make two different
view controllers?
If you have very different UI between the two devices, it is wiser to use two different view controllers, and to create the right one at runtime (in the application controller for example) by using the UI_USER_INTERFACE_IDIOM macro.
I had pretty good luck with just selecting the target then going to Project->Upgrade current target for iPad.
My app is pretty simple, consisting mostly of table views and webviews, but it's worth making a backup and trying...
And yes, you have to submit it as a 3.2 app that can target 3.1.*
There are also a lot of other stuff that you have to do:
Make sure that it can be viewed at any orientation (got rejected the first time for this).
Make sure that you have all the new images created. you have to have 3 or 4 icons, instead of just one like an iPhone app needed. (iPad icon, iPhone icon, small icon for spotlight, etc).
And of course iPad sized screenshots for the store.
A really nice way that I use to test if it's an iPad or iPhone is to check if the device can use a split view controller, since for the forseeable future no device with a screen as small as an iPhone will be able to use the split view controller. I just created a function to do this for me:
+(BOOL)isIpad{ return NSClassFromString(#"UISplitViewController") != nil; }
Then anywhere in my app that I want to display something different depending on device, I just do a check for it:
int width = 150;
if([NabAppDelegate isIpad]){
width = 350;
} else {
width = 150;
}
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5,10,width,25)];
This is a lot better than checking against OS version like I've seen some suggest.