How to copy entire XCode project for another device? - iphone

Ok, I have an iPhone project that utilizes the camera.
I'm trying to utilize 80% of the same code for an iPad version of this project, however, I have to change some values as the camera quality in the latter device is messing with some parameters which I used as criteria for the first device.
So what I did was: I duplicated the iPhone project and had two targets in total, in the same project, the first one - for the iPhone (the original), and the second for the iPad.
When I clicked on the second target and added a comment on some .m file, the same comment appeared in the same .m file in the iPhone version's file too.
I don't want that - as you can see, I want a separation. I want to use the iPhone project as a base to modify the code of the iPad project. But how do I do this ? If the comment appeared in the iPhone .m too then obviously that means there is no distinction , and that whatever I do in the iPad .m will mess up the other .m ?

it looks like your two projects are sharing the same files. If you want to keep them separate, just duplicate the source files and add them back to the projects individually.

I'd create a universal app. That way you can share all of your code between the two devices in a single project. Then you can simply separate logic for each device type into different files. So for example, have ViewControllerA for both device, and ViewControllerA_iPhone and ViewControllerA_iPad for the each separate device.

Possible duplicate:
Conditional Compilation between ipad and iphone
I think you don't need a second implementation file, you just need to compile for a different device or check which one you are on at runtime and adjust accordingly.

I think don't need to copy the entire project. You can just copy the necessary files only and create logical groups for iPhone and iPad. Check the device type into appdelegate class if it is iPad then call iPad related class else iPhone. Hope it will help you.

it sounds to me like you need to 'extend' the functionality of the original to incorporate the new.
Would it not be easiest to create the 'interface' and then an base form of the class (maybe make it abstract), that implements all the methods, but leaves those that may have special needs (just have them throw an error as basic method functionality)
Then for the 2 projects you can extend the abstract class and overide the methods adding in the functionality that you require.
The beauty is that if there is an error condition in the overidden methods you can just call the 'superclass' abstract method and throw out the error message, you may decide that the super class method should take a string input variable to enable you to use a customised message taged onto the end of the one in the abstract class.
David

Related

Define Layout, GUI by Code at Runtime

Net Developer planning a new Product.
It will amongs other things generate dynamically its User Interface from a downloaded File.
I read that file and depending on it i create the necesseray buttons, labels, tables etc..
I wish to outsource that similar kind of product for a development for the IPhone..
So my question to Iphone experts is. Is this possible with the Iphone too?
With 'possible' I mean basically if it is technically possible and if it is 'allowed' on MacStore..
Any feedback is much appreciated...
The user interface files on the iOS, the (the XIB files), are nothing more than a files containing archived objects. So when you create a static interface in Interface Builder, what Xcode actually does is to create objects for all the UI elements, setting the object properties according to your wishes, setting up the object graph (which objects has references to which other object) and finally archives the whole graph into a file. When you load a XIB file, the objects are simply unarchived and you get an object graph with all the UI objects in their desired states.
That means whatever can be done by loading an interface from a XIB file can also be done problematically. All you have to do is creating the objects yourself, setting all the properties as desired and chaining them to the desired object graph. And yes, creating UI problematically is absolutely allowed by the App Stores (for Mac and for iOS), since it does the same thing by hand as loading a XIB file does automated.
Yes, it is possible and allowed. There are very little UI related operations that can't be done programatically on Cocoa Touch.

xcode not creating different app Delegate for universal app

i am totally new to iphone and i am trying to create a universal app.
Now I am creating an empty application. According to all tutorials , by checking universal option it should auto create appdelegates for both iphone and ipad.
But all i can see is only one appdelegate . Kindly tell me how can i create both.
Best Regards
Brayden is correct in answering that you almost never need multiple app delegates. All the delegate usually does is handle the moments when the application launches, suspends or terminates. Back in the days when iPhones ran iOS 4.0, and iPads ran iOS 3.2, you might need very different code in the delegate because only iOS 4.0 supported multitasking. Those days are long gone, and your delegate should probably act the same on all devices.
Yes, you sometimes do reach a point where your program must behave differently on iPhone and iPad. Check the idiom at that time and no earlier. Otherwise you're just duplicating code to no purpose.
My most recent app contains almost no special checks for iPhone or iPad. It doesn't even use different XIBs. Instead, my custom views implement layoutSubviews to fill the space available.
That said, once you understand app delegates, maybe you will find a situation where you need them to be different. If you are absolutely certain that your iPhone and iPad behavior will be so wildly divergent, you will need to:
Manually create a new class (preferably inheriting from the existing AppDelegate class)
In your main.m, send the class name of your new delegate to UIApplicationMain depending on the idiom.
See this answer to "Can I create App Delegate file in my project?" to see the changes to main.m.
You really should only be using one AppDelegate for a Universal application. You can use this to share common things that you'll do in there. What exactly do you need multiple AppDelegates for? If you need to do something specific to a device type (i.e. - iPhone or iPad) then you can do a ternary expression like below:
(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? NSLog(#"iPad") : NSLog(#"iPhone");

Zxing Library for Iphone

Can I use the ZXing Library and scan a qr code in the background of my iphone app? I do not want the camera overlay with the square that looks for the qr code and the cancel button (as is shown in the ScanTest Example). What I need is that pressing the scan button will activate the reading of the QR code, and when the QR Code is read, how do I return the text to my application, so I can display it in a UILabel on the screen.
Can anyone show some example code in Objective-C for this? Thanks.
I did something similar, and can provide you with some guidance, but can't share source code.
Take a look at ZXingWidgetController.mm,.h files. This is a fully functioning QRcode scanning app that you can compile, so it can be reverse engineered into just containing the backend code. Edit the .h so the class extends NSObject instead of UIViewController, then delete any class properties and instance variables that are GUI objects.
That will cause xcode to find and mark all the methods and variables that you no longer need with warnings/errors in the .mm file (willAppear, etc.). Most of this code can be deleted, but be mindful to move allocations/deallocations to constructors/deconstructors.
In the viewController you can create an instance of this class, and call the class to start scanning. You need to modify the didDecodeImage in the ZXingWidgetController.mm file to do what you want it to do when it successfully gets a result from the QR code. One possibility is to modify the constructor to take your parent view controller as a parameter, store it in an instance variable as a delegate (__weak), then use that to call one of its functions in the didDecodeImage method. Other people might pass the data back to your main code using notifications.
Hope this helps!
There are a set of classes in the zxing objc directory that operate at the CA level rather than the UIView level that might be easier to modify than the widget, which operates at the UIViewController level.
This would still take a little tweaking, though, because the core capture code tracks whether the view is on screen or not to automatically start and stop the capturing of frames.

Building app for iPhone and iPad

Can any one suggest how I can build Universal app for iPad as well iPhone. What all things I should take care of ? How to take care of resource images used ? Is it possible to have same code base should work for iPad as well iPhone.
In the Target->Project->getInfo->Build->target family-> select iPhone/iPad
And make the conditions everywhere whereever you set frame and also the resolution of the image required by iPAD is high.. so as per condition check whether its running on iPad or iPhone and based on that set your frame and image.
hAPPY cODING...
After creating your universal app (see #Suriya's post above) you should figure out in the app delegate whether you have an iPad or iPhone. Here is a simple tutorial to do just that.
Yes, you will need separate nibs and images for an iPad app. But, no, not all the code has to change. You can simply use class inheritance.
Example:
You have a MyTableViewController.h and .m file that work on the iPhone. This table has a custom cell, MyTableViewCell. Now you want your iPad app to get the same information, but display a larger table and a larger table cell. You then subclass your iPhone classes like so: MyiPadTableViewController : MyTableViewController and MyiPadTableViewCell : MyTableViewCell . This way you have access to all of your created functions in the parent class, but you can override how the information is displayed.
If you have a function - (void)doSomething:(id)foo; in your MyTableViewController class, you can use it in your MyiPadTableViewController class without writing any extra code, or override it if necessary. The point is you don't have to change code in two places, so it makes life a lot easier.

How to convert nib/xib to objective C code?

I am just wondering is there a way to convert nib/xib file to ojbective C code? I just want to find the equivalent code to the nib/xib file (I've tried nib2objc, seems the result is not what I am after).
Actually I want to compile this example
http://developer.apple.com/iphone/library/samplecode/TableSearch/index.html
without nib/xib file (I want it exactly the same with original), any idea about doing this?
Check out nib2objc:
nib2objc converts NIB files (or XIB ones) into Objective-C code, including all the properties of each instance, the documented constructor calls, and also the view hierarchy.
nib2objc yourfile.xib > code.m
In the general case, I think the answer is no. Nibs are not code; they're archives of serialized objects. So what you're asking is, "Given a graph of arbitrary serialized objects, can I generate some source code that might create such a graph without using serialization?" Without special support for such a process in all classes involved, I don't see how you could.
It would probably be more beneficial to ask about what you actually need to accomplish rather than this specific way of doing whatever it is.
To all the 'There shouldn't be any reason to not use a nib/xib' type responses here, let me provide a concrete example as a counterpoint.
[iPhone OS 3.1.3, 3.2]
iPhone OS apps have a limited amount of memory to work with. If you use too much your app is automatically terminated by the OS.
Interface builder loads images referenced in a nib/xib into a cache using [UIImage imageNamed...], which uses up memory and does not automatically release that memory. There is also no way for you to request those images in that shared cache be released.
Lay out some large images in nib/xib files (i.e. - backgrounds), in an app with multiple nib/xib files, and you will very quickly have an app which gobbles up memory quickly (3mbs per full size png background on iPad), that you have no control over releasing. Any doubts about this, check the documentation for [UIImage imageNamed] and do some googling to verify that is what is used.
That's a case for not using a xib/nib.
I think it makes sense to do this if you just want to create a starting point for a view that is created programmatically in a way that isn't easy or possible to do with Interface Builder. It is also convenient if you want to bundle the view hierarchy in to a static library so that it is fully self-contained. Ideally you want to use nibs if possible though. It will make internationalization easier. However you can still support internationalization with a strings file.