iOS full/lite version using multiple windows - iphone

I have two targets in my Xcode 4.3 project. Each target has its own X-info.plist file. I would like to have two windows (MainWindow.xib), one for the full app and one for the Lite version. I set the Main Interface for each target and also Main nib file base name in the X-info.plist but it's not working. What did I miss?
Thx

You can add a Preprocessor Macro to the target of the lite version LITE=1. Then in your code, when you want to execute something differently you can use #ifdef, for example:
NSString *mainWindow;
#ifdef LITE
mainWindow = #"MainWindow_Lite";
#else
mainWindow = #"MainWindow_Full";
#endif
// Load nib with the name mainWindow.
// Or load ads in the lite version
// Or disable functionality in the lite version
//
If you want to avoid doing that and want to use the same name for the two nibs, you have to add one of them as a member of the full target and the other one as a member of the lite target.

You can easily have the even same names for .xib files for different targets. Just make sure that two files with the same name aren't members of the same target. They have to be placed in different directories on HD and in different groups in project.
There is also a known bug with IB (image resources and so on) and multiple targets: see more at Two targets with separate .xib (image resources with same names)
But this information is for XCode 4.2.x, not sure if it/s valid for XCode 4.3

Related

AppClip easy way to target all needed files

I am building AppClip app based on existing project. My question is - Is there an easy way to target all files which my couple of screens are depending on?
For example
I need add OrderViewController to an AppClip. This screen depends from OrderViewModel. OrderViewModel depends from BaseViewModel and NetworkManager. And so on, and so on, and so on...
By "depends from" I mean File_A using inside code from File_B. And to compile a target with File_A I need to include File_B too, to a target. And as you can imagine there might be a lot of dependency files. But I am lazy. And looking for some magic ;)
You can add the files you need (OrderViewController, OrderViewModel, NetworkManager ...etc ) in your targets like the Main app and the app clip like that
then define the custom compilation conditions with any name you like in my case I made it
APPCLIP
after that use (compiler directives) to differentiate between the main app and app clip like that
#if !APPCLIP
extension AppDelegate:MessagingDelegate{
}
#endif
in the main app, I use MessagingDelegate but in the app clip I don't so, I write a case to check if the app is running app clip or main app
here are some resources that could help you
https://needone.app/compiler-directives-in-swift/
https://betterprogramming.pub/how-to-build-an-app-clip-on-ios-14-a5045fd68eb4
https://medium.com/swlh/ios-14-app-clips-95bfaf2b159c

Universal App Loading Different Views

Trying to make an existing app having two different set of .h .m and .xib files for each view. Now for a single view am using only one .h & .m file and two .xib file.
eg.
ViewController.h, ViewController.m, ViewController~iphone.xib, ViewController~ipad.xib
Problem: At compile time i get errors for the files in my code i have not set their target for iphone and ipad both.
Go to Project -> Targets -> Build Settings -> Targeted Device Family . Set it to iPhone/iPad.
Enjoy Programming!!
Better solution is add target device for existing class

Why does resource bundle copy .png as .tiff images?

I've created a static library and a resource bundle for reusing code and assets across several projects.
Within the static library, I have a manager class whose sole purpose is to create other UIViewControllers, whose views are created from .xib files (using the common initWithNibName:bundle: method).
When I create the view in Interface Builder, the images show correctly. However, when I run the app on the simulator, I get this error:
Could not load the "<image_name.png>" image referenced from a nib in the
bundle with identifier "com.<my_company>.<app_identifer>"
After hours of grinding, I finally inspected the resources bundle, and I found that the .png files weren't in it! Instead, .tiff files of the same name (excluding #2x versions) were there instead.
All of the images are included within the bundle's build phase under copy bundle resources , and I've used the images on other iOS projects (so they're not corrupted).
Has anyone else experienced this? Is it safe to assume that the images will always be added to the bundle as .tiff? (And if so, is it safe to just change the image name in interface builder to .tiff?) Or am I doing something incorrect here?
Thanks for your help in advance.
For the issue of resource bundles , refer to this link as it has a couple of similar faced queries.
Conversion Resource bundle
Tell me which answer really helped you solve this issue. Thanks.
This Solved my problem
In your bundle target Go to,
Build Settings > COMBINE_HIDPI_IMAGES and set to NO

Referencing Classes from Different Targets in xCode for iPhone Unit Testing

I am trying to unit test my iPhone application. I have created a new target and called it "LogicTests". But now I need to use a class called "Spaceship" inside the test. How can I do that?
UPDATE 1:
I made the Spaceship.m available to the unit testing target and that particular error was gone. Now I have different problem. The Spaceship.m file reference to the Cocos2d library. How can I add a reference to the Cocos2d library in the unit testing target. I tried right clicking the Link binary with libraries option and then adding the cocos2d framework but it gave me 153 errors or something.
To include it in that target, click on Spaceship.m, get the file's Info (Command-I), and make sure "LogicTests" is checked under the Target tab.
Beyond that, make sure you add
#import "Spaceship.h"
To the top of the particular test class. Good luck!
In Xcode 4 you press: Alt-Command-1 and then check that "LogicTests" is checked under the Target Membership tab.

Packaging a Bundle with a static library

I have a static library that includes some xibs. These will basically be the same across projects. I'd like to include the xibs as part of the library. I can include their veiwcontrollers, reference these controllers in the calling project but then there isn't a xib to load. When I right click the xib in the library project, it can't be part of the target.
I thought about creating a CFPluginBundle but that creates a new project. I'd loose all of my IBOutlet and IBAction references. What is the best way to reuse xibs that also have outlets and actions to specific controllers?
Here more discussion about it: Can you reference Xib files from static libraries on the iPhone?
I had the same problem when I wanted to export my project as a library for other developers to use.
I found the perfect solution to my view and it seems it will answer yours too.
There is an xcode plugin that allows you to build your project as a library which includes the resources as well.
https://github.com/kstenerud/iOS-Universal-Framework
I do not know the guys that built this plugin, but it works like a charm
I'm not sure what you mean by "include the xibs as part of the library", since static libraries can't have resources--but they also aren't shipped stand-alone, so they don't need to. If you just want code re-use for your own projects, you could keep the xibs where-ever you keep the static library, and just include the xibs in any project that uses the library.
If you go the CFPluginBundle route, you can make new bundle targets in an existing project; there's nothing magic about the templates, they just take care of making dummy files and turning on the right build settings. You can copy those into a new target in your existing project and it will work just fine. That said, I'm not sure what you mean about losing IBOutlet and IBAction references, since that information is part of the xib (and the class you are using in the xib), not the project.