iPhone zXing QR Scanner - didscanresult function never fires - iphone

I have loaded the zXing project into my own project.
It loads fine, the zXing scanner pops up after a button call.
I can dismiss the view controller on thezxingControllerDidCancel but when I scan a QR code, no codes are ever recognised and therefore the didScanResult function never fires.
Does anyone have any idea about this one?
The didScanResult function is below.
-(void)zxingController:(ZXingWidgetController *)controller didScanResult:(NSString *)result{
resultLabel.text = result;
NSLog(#"did scan!!!");
[self dismissModalViewControllerAnimated:NO];
}
Note: I'm not sure if this is relevant, but when the scanner comes up, I get this logged by the app: "wait_fences: failed to receive reply: 10004003"

That tutorial does not mention that you must add a QRCodeReader to the set of readers of your ZXingWidgetController.
ZXingWidgetController has a property called readers, which is an NSSet containing the instances of the readers (e.g. an instance of QRCodeReader). Roughly, the readers' task is to analyze the images your camera takes and to extract the encoded information. Your ZXingWidgetController has to know about the readers it should utilize, otherwise it has no chance to do anything meaningful. So you have to set the readers property before you present the ZXingWidget.
The ZXing project has a sample app which demonstrates this. If you use ARC, then
ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
QRCodeReader* qRCodeReader = [[QRCodeReader alloc] init];
NSSet *readers = [[NSSet alloc] initWithObjects:qRCodeReader,nil];
widController.readers = readers;
[self presentModalViewController:widController animated:YES];
should do.

Related

Initial text and paperclipped-URL for action in UIActivityViewController & UIActivityItemSource?

Finally been making it through Apple's (rather dismal) documentation on the new UIActivityViewController class and the UIActivityItemSource protocol, and I'm trying to send different data sets to different actions called from the activity view. To simplify things, I'm looking at two things.
A Facebook posting action, which should say "Check this out!" and also attach a URL to the post (with that cute little paperclip).
A Twitter posting action, which should say "Check this out, with #hashtag!" and also attach that same URL (with the same paperclip).
Here's the code I've got implemented right now.
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
return #"Check this out!";
} else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
return #"Check this out, with #hashtag!";
}
return #"";
}
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return #"";
}
And then when I set up this activity view controller (it's in the same class), this is what I do.
UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:#[self] applicationActivities:nil];
[self presentViewController:activityView animated:YES completion:nil];
My dilemma is how to attach that NSURL object. It's relatively easy when calling the iOS 6 SL-class posting modals; you just call the individual methods to attach a URL or an image. How would I go about doing this here?
I'll note that instead of returning NSString objects from -activityViewController:itemForActivityType, if I return just NSURL objects, they show up with that paperclip, with no body text in the post. If I return an array of those two items, nothing shows up at all.
Evidently it was as simple as this: passing in an array to the first argument of UIActivityViewController's init call, with each item in the array handling a different data type that will end up in the compose screen. self handles the text, and the second object (the NSURL) attaches the URL.
NSArray *items = #[self, [NSURL URLWithString:#"http://this-is-a-url.com"]];
UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self presentViewController:activityView animated:YES completion:nil];
Really wish there was more on this, but here it is.

How to implement multiple download code objective c

Im sorry, i feel kind of dumb, but im having trouble implementing the following code for to download multiple files from the server.I have set up the MultipleDownload.h and MultipleDownload.m files as a new Objective-C class within my app. But not sure how call it from my updateView.m to perfrom the file downloads. As per instructions it says i need to initialize and start downloading with the following lines. I cant figure out where to put that code to start downloading files from urls. Do i have to setup a method within that MultipleDownload.m code and call that method it from another object (updateView.m) to initiate the download? or i do i put those lines into one of the methods in (updateView.m)? I honestly tried both and for some reason i keep getting errors, It says that urls. If i put it in updateView.m it says that self.urls and self.downloads is undeclared identifier. I tried to declare NSMutableArray *urls and MultipleDownload *downloads within my updateView.m and it doesnt seen to work either. Any input would be appreciated.
the MultipleDownload.m and MultipleDownload.h code is located on github:
http://github.com/leonho/iphone-libs/tree/master
To initialize and start the download:
self.urls = [NSMutableArray arrayWithObjects:
#"http://maps.google.com/maps/geo?output=json&q=Lai+Chi+Kok,Hong+Kong",
#"http://maps.google.com/maps/geo?output=json&q=Central,Hong+Kong",
#"http://maps.google.com/maps/geo?output=json&q=Wan+Chai,Hong+Kong",
nil];
self.downloads = [[MultipleDownload alloc] initWithUrls: urls];
self.downloads.delegate = self;
What you do is in updateView.h
create #properties for urls (type NSMutableArray) and downloads (type MultiDownload)
then in updateView.m you add a these functions
//Function to start download
- (void) startDownload
{
self.urls = [NSMutableArray arrayWithObjects:
#"YourURLS",
#"YourURLS",
#"YourURLS",
nil];
self.downloads = [[MultipleDownload alloc] initWithUrls: urls];
self.downloads.delegate = self;
}
//download finished for 1 item
- (void) didFinishDownload:(NSNumber*)idx {
NSLog(#"%d download: %#", [idx intValue], [downloads dataAsStringAtIndex: [idx intValue]]);
}
//download finished for all items
- (void) didFinishAllDownload {
NSLog(#"Finished all download!");
[downloads release];
}
I also suggest that if you have problem understanding self.urls and self.downloads to read some more info about objective c and properties, good luck

How to use the existed sample application to integrate google credentials in the iphone app

From the below link I download the .zip file it contains some example. In that I played the OAuthSampleTouch application.
http://code.google.com/p/gdata-objectivec-client/downloads/list
This is the file I downloaded :
gdata-objectivec-client-1.11.0.zip
I gone through it but I am getting confusion how to pass input that is email and password and then how to connect through google form my iphone app.
Newly edited code:
This is code from OAuthSampleTouch example in the class "OAuthSampleRootViewControllerTouch.m" Please refer http://code.google.com/p/gdata-objectivec-client/downloads/list in that OAuthSampleTouch application.
- (void)signInToGoogle
{
[self signOut];
NSString *keychainAppServiceName = nil;
if ([self shouldSaveInKeychain])
{
keychainAppServiceName = kAppServiceName;
}
// For GData applications, the scope is available as
// NSString *scope = [[service class] authorizationScope];
NSString *scope = #"http://www.google.com/m8/feeds/";
// ### Important ###
// GDataOAuthViewControllerTouch is not designed to be reused. Make a new
// one each time you are going to show it.
// Display the autentication view.
GDataOAuthViewControllerTouch *viewController = [[[GDataOAuthViewControllerTouch alloc]
initWithScope:scope
language:nil
appServiceName:keychainAppServiceName
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)] autorelease];
// You can set the title of the navigationItem of the controller here, if you want.
// Optional: display some html briefly before the sign-in page loads
NSString *html = #"<html><body bgcolor=silver><div align=center>Loading sign-in page...</div></body></html>";
[viewController setInitialHTMLString:html];
[[self navigationController] pushViewController:viewController animated:YES];
}
This is code from OAuthSampleTouch example in the class "OAuthSampleRootViewControllerTouch.m" Please check it. What is the scope and from where I need to pass credentials. If I run this I am getting the log as Authentication error:
Please help me, I am trying it from three days.
Any help is much appreciated.
Thank you,
Madan Mohan.
Search for this method
(GDataServiceGoogleContact *)contactService
Here you will be giving username and password for google account..

I'm having issues inputing a name if applicable

I have a function here that upon completing a single round, if your score is higher than either a default score entry or a newly placed high score then it will swap its data with your data and push everything else down. removing the last entry from the list. currently this is just one exchange and for functions sake I'm going to hard code it and then refactor it later.
My main problem is that when I set up a text input view to capture the players name execution continues immediately without the players input and crashes the game. I commented out the line that sets the text because I have a default value in place just in case any attempt that I try to make fails. How can I get Execution to wait for a moment while input is taken? Would I have to set up a delegate method? If so I'm still a bit confused by delegates. I could set it up to work but I don't understand it, so I wouldn't be able to do any other special custom tasks with it. I've worked on it for a while and got no further...
-(void)saveData:(ScoreKeep *)stats{
NSMutableDictionary *swap = [[NSMutableDictionary alloc]init];//used for swaping entries
NSString *filePath = [self pathOfFile];
NSLog(#"Writing to %#", filePath);
if ([[NSFileManager defaultManager]fileExistsAtPath:filePath]) {
NSLog(#"Loading previous dictionary to save...");
dataDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
if ([dataDictionary objectForKey:#"1"]) {
NSMutableDictionary *highScore = [dataDictionary objectForKey:#"1"];
if ([stats.score intValue] > [[highScore objectForKey:#"SCORE"] intValue]) {
NSLog(#"You Win! score: %# highscore: %#", stats.score,[NSNumber numberWithInt:[[highScore objectForKey:#"SCORE"] intValue]] );
stats = [[ScoreKeep alloc] initWithNibName:#"Scorekeep" bundle:nil];
NSLog(#"Setting up name entry");
[self.view addSubview:stats.view]; //New view is added so that the player can input data(Assume it is complete);
//stats.nameTag = setName.nameTag;//This line is executed before the new view is dismissed causing an error to occur
[stats setupDictionary]; // It just goes down hill from here if the previous line is uncommented
[dataDictionary setObject:stats.sComponents forKey:#"1"];
}else {
NSLog(#"You Lose: %# highscore: %#", stats.score,[NSNumber numberWithInt:[[highScore objectForKey:#"SCORE"] intValue]] );
}
NSLog(#"Got first place entry");
}else {
NSLog(#"Initilizing Score");
}
}else{
NSLog(#"Creating new dictionary to save...");
dataDictionary = [[NSMutableDictionary alloc]init];
}
[dataDictionary writeToFile:filePath atomically:YES];
}
Help would greatly be appreciated. If more information is needed I'd be happy to provide.
by the way ScoreKeep is an object that contains a dictionary and a function to create a dictionary such that it can set any values I need and package them into sComponents(the dictionary to be entered into the main savefile)
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#class omphalosUtility;
#pragma mark -
#pragma mark Saving data
#pragma mark -
static inline void poop(){
NSLog(#"POOP");
}
I'm going to try making a utility file that works independently of the app so that I Can update files and perform other universal operations such as saving when needed. Its a step in a direction that i'd like to take.
If i get it right, (The code is really nasty, man...) your problem is that you are trying to present a View Controller with the wrong way.
Correct me if i'm wrong, is ScoreKeep is a ViewController? if so, you have to name it properly. that's for a start.
Second, you cant present another view controller only by adding its "view" property to the current view controller's View Hierarchy. that way the view will not respond properly to the events.
the correct way to to what you'r trying to do is by presenting the ScoreKeep ViewController modally.
there is no other right way to do this without using delegation. you will have to acquire this technique.
Your view controller that responsible for getting the name from the user need to have a way to tell it's master view controller that the user entered a name. and that is achieved through delegation.
What you should do:
Basically you create a protocol called something like "NamePrompterViewControllerDelegate"
that will have at least one method that will be called when the user will done entering his name.
Your ScoreKeepViewController should have an instance variable that implemented the protocol (Look at the apple documentation on protocols for assistance)
Your main view controller (the one that contains the method you added) then should implement the protocol you created, and set itself as the delegate of ScoreKeep like that:
stats = [[ScoreKeep alloc] initWithNibName:#"Scorekeep" bundle:nil];
stats.delegate = self;
For more info on presenting and dismissing ViewControllers modally you should read the documentation at Apple Documentation
I hope i helped you, there is just a lot to cover and it hardly can be done by writing an answer.
Feel free to ask more for clearance.

iPhone SDK NSInternalInconsistencyException

I'm hitting a wall over and over again, trying to solve a problem I've got in xcode. I'm a newbie and started coding just a while ago.
I'm trying to make a XML parser based on this tutorial: http://cocoadevblog.com/iphone-tutorial-creating-a-rss-feed-reader
which works fine separately, but when I'm implementing it into my own project, I get the 'NSInternalInconsistencyException' error, as a result of the following code:
----File: Parser.m----
- (void)parserDidEndDocument:(NSXMLParser *)parser {
if ([_delegate respondsToSelector:#selector(parsedInformation::)]){
[_delegate parsedInformation:information];
}else{
[NSException raise:NSInternalInconsistencyException
format:#"Delegate (%d) doesn't respond to parsedInformation:", _delegate];
}
}
I've tried to remove the if-phrase, and then it calls the correct function, but the data which is supposed to be overhanded, won't get through.
Project setup
The project is a tab-based application. I'm having three classes:
Parser
AlphaTab
RootDelegate
In RootDelegate I used the following code to initialize the tab-view, and then to initialiaze the AlphaTab as a tableView being part of a navigationView:
----RootDelegate.m ----
tabBarController = [[UITabBarController alloc] init];
alphaTab = [[AlphaTab alloc] initWithTabTitle:#"AlphaTab" navigationTitle:#"Exploring"];
UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:alphaTab] autorelease];
tableNavController.delegate = self;
[alphaTab release]; // creates your table view's navigation controller, then adds the created view controller. Note I then let go of the view controller as the navigation controller now holds onto it for me. This saves memory.
So good so far.. the problem comes when I use the Parser class, which parses a given XML file. This class is initialized and only implemented in the AlphaTab - therefore it has nothing to do with the RootDelegate class at all. The initialization is done as:
----File AlphaTab.m ----
- (void)loadData{
if(information==nil){
Parser *XMLParser = [[Parser alloc] init];
[XMLParser parseFeed:#"http://frederikbrinck.com/bodil/Example.xml" withDelegate:self];
[XMLParser release];
}else {
[self.tableView reloadData];
}
}
I'm suspecting the parameter withDelegate's value "self" to be the problem, which I think referres to the super class RootDelegate, but I'm not sure. Likewise, I don't know to pass the AlphaTab class' delegate to the function, which I think would solve the problem.
I'm ought to think, that the problem could be created from this line aswell:
----FILE: Parser.h ----
#protocol AlphaTab <UITableViewDelegate>
- (void)parsedInformation:(NSArray *)i;
#end
I've done some research about protocols and respondsToSelector, but honestly, I didn't understand much, since my code is seen from the programmatic perspective of view, without using the InterfaceBuilder at all, since I've been adviced to do that. It hasn't lead to the solution of the problem either.
For further understanding, I then want this function in AlphaTab.m to be called, when the information is parsed.
----FILE AlphaTab.m ----
- (void)parsedInformation:(NSArray *)i {
NSLog(#"The parser has completed parsing");
information = i;
NSLog(#"This is the information: %d", [[information objectAtIndex:0] objectForKey:#"tabTitle"]);
[self.tableView reloadData];
}
I've looked on the net, and I found some explications about the NSInternalInconsistencyException. I've tried to do them as well, for example by setting everybody with themselves as delegates. However, I had no luck. What wonders me most, is that when I use the Parser without having to subclass it's caller (this case: AlphaTab) to a main class, it works like a charm.
I hope you guys can give me a clue. If you need any more information please ask, and I'll be in disposition.
//Brinck10
Please see #warrenm and his comment.