Zxing Library for Iphone - 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.

Related

How to copy entire XCode project for another device?

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

How can we load image like apple is doing in his app store?

Hello guys how apple is loading table view cell image that
doesn't affect scrolling of
table view.How fast it is working. I want to make a table view like that which loads
image directly from URL and it doesn't effect scrolling of UITableview
Lazy Loading is the exact term, which you are referring to. (Apple Technologies uses LazyLoading wherever it can be applicable, whether it's iOS or Mac OS X -- and it gives best user experience, too, as user is not forced to wait)
Apple provides sample source code, which performs similar functionality -- Here is the sample code
Don't get confused with the ParseOperation Class. It is just the separate implementation of the XML Parsing functionality. Though, It is a better approach, You can write it in your own working class (from which you are invoking the connection request.)
Additionally -- Apple has updated this code to use Blocks (GCD).
Hope that will help you...
You dont need to look too far - Apple has this code in the Open - LazyTables.
If you want to know the magic sauce is the launching of bg thread to download images, after the downloads finish in background, then it updates the UI to show the image.

Use accelerometer in a tab app

I would like to use the accelerometer in a tab app. All three tabs would access the current x,y,z and change an mage based on that data. My problem is where does the initialization of the accelerometer go so that all three tabs can update based on the data? The update only needs to happen when you are in the current tab.
I can only get this to 'work' if I initialize 3 accelerometers which is not correct. Would the data go in my appdelegate and the code to change the images in each nibs view controller?
Try to avoid putting code into appdelegate. Try using appdelegate only to handle basic stuff.
I would recomend you to implement a Singleton-Class for your Accelerometer Data.
Singletons are a very basic design pattern, that come in handy especiall in the environment of mobile devices (fewer ressources than a pc)
you can read about the singleton Pattern here: Wikipedia: Singleton Pattern
also there is a very easy way to synthesize a singelton class in your project
include the follwing file into your project syntesizesingleton.h
and within your accelerometer class put the following
#implementation yourAccelerometerClass
SYNTHESIZE_SINGLETON_FOR_CLASS(yourAccelerometerClass)
afterwards within your view controllers (or wherever) you can acces the singleton-accelerometer class by dong things similar to the following:
[[yourAccelerometerClass sharedyourAccelerometerClass] yourMethod];
hope that helps.
sam

App development: Always subclass, always load from NIBs - caveats?

This is Cocoa Touch (et al), iPhone, XCode only.
After completing my first commercial iPhone app, I'm struggling a bit to find a way to start and expand an app from scratch which gives the most linear development (i.e., the least scrapping, re-write or re-organization of code, classes and resources) as app specs change and I learn more (mostly about what Cocoa Touch and other classes and components are designed to be capable of and the limitation of their customization).
So. File, New Project. Blank window based app? Create the controllers I need, with .xib if necessary, so I can localize them and do changes requested by the customer in IB? And then always subclass each class except those extremely unlikely to be customized? (I mean framework classes such as UIButton, CLLocation etc here.)
The question is a generic 'approach' type question, so I'll be happy to listen to handy dev practices you've found paid off. Do you have any tips for which 're-usable components' you've found have become very useful in subsequent projects?
Clients often describe programs in terms of 'first, this screen appears, and then you can click this button and on the new screen you can select... (and so on)' terms. Are there any good guides to go from there to vital early-stage app construction choices, i.e. 'functions-features-visuals description to open-ended-app-architecture'?
For example, in my app I went from NavBar, to Toolbar with items, to Toolbar with two custom subviews in order to accommodate the functions-features-visuals description. Maybe you have also done such a thing and have some advice to offer?
I'm also looking for open-ended approaches to sharing large ("loaded data") objects, or even simple booleans, between controllers and invoking methods in another controller, specifically starting processes such as animation and loading (example: trigger a load from a URL in the second tab viewcontroller after making sure an animation has been started in the first tab viewcontroller), as these two features apply to the app architecture building approach you advocate.
Any handy pointers appreciated. Thanks guys.
Closing this up as there's no single correct answer and was more suitable for the other forum, had I known it existed when I asked :)
If you want to know the method I ended up with, it's basically this:
Window-based blank app
Navigation Controller controls all, whether I need to or not (hide when not used)
Tab Bar Controller if necessary
Connect everything <-- unhelpful, I know.
Set up and check autorotation, it might get added to some view later.
Add one viewcontroller with xib for each view, you never know when they want an extra button somewhere. It's easier to copy code than make the max ultra superdynamic adjustable tableviewcontroller that does all list-navigation, etc.
Re-use a viewcontroller only when just the content differs in it, such as a detail viewcontroller.
Minimize code in each viewcontroller by writing functions and methods and shove them in a shared .m
Everything that's shared ends up in the App delegate, except subclassed stuff.
Modal viewcontrollers are always dynamically created and never have an xib.

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.