My qrcode scanner not able to scan specific URL containing special character - iphone

I am able to scan all qrcodes for the urls however some urls containing special characters such as "%20" are not getting scanned and it crashes the app. I am using ZBarSDK for scanning and ZBarReaderView is the scanner.
http://www.winlogisticsmedia.com/images/bigkmr%20end%20sale.jpg is the URL which when made on qrcode, my app crashes and it shows the below window.
P.S: One more thing is that I think on which I am getting the scanning report (text) is a nsstring. Is there any chance relating to it as its an string and the text consists of numerics and special characters?

I was having the same issue. My app would crash when I would log the AVMetadataMachineReadableCodeObject stringValue.
My original code that would crash:
NSLog("%#", [machineReadableCodeObject stringValue]);
Once I decoded the stringValue with stringByReplacingPercentEscapesUsingEncoding it does not crash anymore:
NSString* decodedValue = [[machineReadableCodeObject stringValue] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog("%#", decodedValue);

Related

how can i query google places for country specific cuisine?

i am trying to accomplish country specific Cuisine places, means like mexican food, spanish food, Thai food, indian food, via google places API on an iPhone app.
How can i do that?? As i see supported types, there is only food, restaurant, etc in it. besides whenever i use this query..
NSString *url = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%#&type=restaurant&query=%#&sensor=true&key=%#", currentCentre.latitude, currentCentre.longitude, [NSString stringWithFormat:#"%i", currenDist], googleType, kGOOGLE_API_KEY];
i am getting few results only, whenever i try to add more types like food|restaurant|establishment like below query my app crashes.
NSString *url = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%#&type=food|restaurant|establishment&query=%#&sensor=true&key=%#", currentCentre.latitude, currentCentre.longitude, [NSString stringWithFormat:#"%i", currenDist], googleType, kGOOGLE_API_KEY];
As i told my app crashes with this error may be i am doing something wrong with url.
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
* First throw call stack: (0x13be022 0x200fcd6 0x1366a48 0x13669b9 0xbadfad 0x2dd2 0x13bfe42 0xaa09df 0x139294f 0x12f5b43 0x12f5424
0x12f4d84 0x12f4c9b 0x15d47d8 0x15d488a 0x17a626 0x236d 0x22d5)
terminate called throwing an exception(lldb)
Please can someone guide me with this?? i hope i cleared all my points.
Thanks & regards,
Malhaar
It appears you are trying to use the Places API Textsearch as you are using the query parameter. If this is correct make sure you are hitting the correct backend:
maps.googleapis.com/maps/api/place/textsearch/json
Also make sure you are using the correct parameter to specify types:
types=food|restaurant|establishment
I would recommend reading the documentation thoroughly and and performing a few test html requests through your browser to make sure you have the right request before plugging it into your application.
Although this is almost 7 months old, and I'm sure you've either solved it or given up on it by now, I have just had the same issue and it took some resolving. I thought I'd put the answer here to help anyone else with a similar error.
The problem I found was to do with the URL encoding not liking the | character.
The way around it I found was to:
// Create an NSString with the URL which includes the '|' characters.
NSString * urlString = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=51.189781,-114.488907&radius=6918&types=food|bar&keyword=&sensor=true&key=YOUR KEY HERE";
// Encode the URL
NSString* encodedURLString = [urlString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
// Covert to a NSURL
NSURL *googleRequestURL=[NSURL URLWithString:encodedURLString];
And then use the googleRequestURL as the URL.
Hopefully that will solve it for you!

iPhone - Xcode - Invalid CFArrayRef when searching Address Book for a symbol

I'm trying to filter contacts using a search bar each time a user enters a character. This works fine for regular characters, but when a symbol is entered like $ or ( for the first character, ABAddressBookCopyPeopleWithName returns an "Invalid CFArrayRef". I've searched a while for the solution and I can't seem to find anything. The code is below.
CFArrayRef filteredContacts = ABAddressBookCopyPeopleWithName(addressBook, (CFStringRef)searchText);
CFMutableArrayRef filteredContactsMutable = CFArrayCreateMutableCopy(kCFAllocatorDefault, CFArrayGetCount(filteredContacts), filteredContacts);
CFArraySortValues(filteredContactsMutable, CFRangeMake(0, CFArrayGetCount(filteredContactsMutable)), (CFComparatorFunction)ABPersonComparePeopleByName, (void*)sortOrdering);
contacts = (NSArray *)filteredContactsMutable;
CFRelease(filteredContacts);
I get an EXC_BAD_ACCESS on the second line where filteredContactsMutable is created using filteredContacts. When I debug it, filteredContacts is an Invalid CFArrayRef when a symbol is the first character. The native PeoplePicker created by Apple allows you to search a symbol as the first character, so I know it's possible.
Any input would be appreciated.
first you should not trigger too much OS calls when you start search. load all data once and store it into array then search. and the reason why it crashes it due to nil argument in it cz i thnk no such user name find. try with simple charectrs n tell me if this prblm still exists

decoding problem uiwebview

i am using uiwebview in my application. there are some links when user clicks a http search starts. it works fine but i have problems while getting "%58 den ysnky'ye tepki" it is given as "X'den ysnky'ye tepki". it has problems with % char.
identifier:%58'den%20ysnky'ye%20tepki
decoded identifier:X'den ysnky'ye tepki
i am using stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding to decode the string like that;
NSLog(#"identifier:%#", identifier);
identifier = [identifier stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"decoded identifier:%#", identifier);
how can i get the correct string?
thanks...
It looks like your string may not be encoded properly in the first place. %58 is the correct encoding for the letter “X” (see this ASCII table). As far as I can tell, therefore, the decode is behaving properly.
What are you expecting?

Problem converting NSDATA

I'm a young iPhone developer and I'm trying to write an iPhone app that syncs data from a server side app on my mac, basically text data.
I'm having trouble reading data on the iPhone side with the following:
`
(void)connectionReceived:(NSNotification *)aNotification {
NSFileHandle *incomingConnection = [[aNotification userInfo] objectForKey:NSFileHandleNotificationFileHandleItem];
[[aNotification object] acceptConnectionInBackgroundAndNotify];
NSData *receivedData = [incomingConnection availableData];
NSString *theString = [[[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding] autorelease];
`
I need to print out theString to a text label on the iPhone, but what I get is the exact "hex code translation" of the text entered on the server side app and I don't seem to be able to convert it to char.
Can anyone help ?
I don't know the answer - but there are a few things to look at or try:
Did you try converting into something other than UTF8? (Unicode? ASCII?)
In the hex output it gives you - I assume it is giving a UTF8 representation - i.e. one 8-bit (two hex nibble) code for each character in your string. Is this the case? Are the hex codes "correct" for a UTF-8 or ASCII representation of your string?
Are there any "bad" codes in the result?
I am wondering if this is happening because there are characters (maybe even invisable ones - control characters - nulls, whatever) in your string which are making it so iOS can't do a "normal" UTF8 conversion...

iPhone: Reading Text From File and UISegmentedControl

First off, I'm a complete beginner.
That said, I thought an ambitious longer-term project/learning experience would be to create an app that displayed daily quotes, like those cheesy day-by-day calendars our grandmothers have in their bathrooms. I want it to have two per day, each one represented by a tab in a UISegmentedControl. That's the long term. Right now I'd be happy with getting a single day's worth of quotes functioning.
Onto the questions:
How can I get text saved in a .txt or .rtf file to be displayed in a UITextView? Preferably without using 'stringWithContentsOfFile,' since Xcode is telling me that's deprecated.
How can I get content from a different file (or maybe a different portion of the same file...?) to be displayed when the user taps the second segment?
If I can get it running so that those two conditions are met and I understand what's going on, I'll consider the day a success. Thanks!
1.
NSError *error = nil;
NSStringEncoding stringEncoding;
NSString *fileText = [NSString stringWithContentsOfFile:#"/path" usedEncoding:&stringEncoding error:&error];
myTextView.text = fileText;
The error and encoding are optional, and you can pass in nil for both. But if you care about the error, or what encoding the file was in they will have useful info in them after the string is created.
2.
Set the valueChanged outlet in Interface Builder to an IBAction on your controller, such as setSegmentValue:. Then, assuming you have an array of quote strings:
- (IBAction)setSegmentValue:(id)sender {
UISegmentedControl *control = (UISegmentedControl*)sender;
NSString *quote = [quotes objectAtIndex:control.selectedSegmentIndex];
myTextView.text = quote;
}
Even though stringWithContentsOfFile: is deprecated, stringWithContentsOfFile:usedEncoding:error: is not. That is the standard method to use for reading from files.
As for the second question, you simply test the state of the segmented control and perform as action based on it. Admittedly this is a high level answer but should get you going.