1

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.

Crash 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?

crash report of thread

halfer
  • 19,824
  • 17
  • 99
  • 186
Saty
  • 2,563
  • 3
  • 37
  • 88
  • Can you show us the threads that are being called when it crashes? (On the left hand part of your screen where you see "Thread 1" in your screenshot above (this appears WHEN the app crashes) click the areas that say "6 - ..." "7 - ..." and "8 - ..." I think what is causing your crash my be found there... – Albert Renshaw Feb 26 '13 at 03:35
  • I think when the qrcode scanner reads the text it stucks with the %20 which is a space and so it becomes null at that point. – Saty Feb 26 '13 at 03:42
  • I don't understand? And sorry for the confusion about the requested screenshots... haha I meant could you actually click the ones saying "6 -[Scan readerView:......" and "7 -..." and "8 -..." and post screenshots of the code it brings ups (or post the code) – Albert Renshaw Feb 26 '13 at 03:46
  • Post your code for the `Scan readerView:didReadSymbols:fromImage:` method. – rmaddy Feb 26 '13 at 04:00
  • 1
    Buddy, There is nothing to do with the URL, It should be something to do with your code when you get the result from the ZBar lib, if you want to make sure, please scan below QR with ZBar sample app. http://qrfree.kaywa.com/?l=1&s=8&d=http%3A%2F%2Fwww.winlogisticsmedia.com%2Fimages%2Fbigkmr%2520end%2520sale.jpg – Prasad De Zoysa Feb 26 '13 at 04:11
  • Could you please add the code of "- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info" function? then we can have a look whats going on. – Prasad De Zoysa Feb 26 '13 at 04:27
  • One more thing @Prasad...other links are working good if the space(%20) has nothing to do with it. – Saty Feb 27 '13 at 10:09
  • - (void) readerView: (ZBarReaderView*) view didReadSymbols: (ZBarSymbolSet*) syms fromImage: (UIImage*) img { for(ZBarSymbol *sym in syms) { resultText= sym.data; NSLog(resultText); break; } if([resultText hasPrefix:@"http"]) { if([defaultaction isEqualToString:@"auto"]){ NSURL *url = [NSURL URLWithString:resultText]; if (![[UIApplication sharedApplication] openURL:url]) NSLog(@"%@%@",@"Failed to open url:",[url description]); } } – Saty Feb 27 '13 at 10:12
  • I tried doing resultText= [NSString stringWithFormat:sym.data]; then I tried logging NSLog, I got "http://www.winlogisticsmedia.com/images/bigkmr 0.000000e+00nd(null)ale.jpg" – Saty Feb 27 '13 at 10:54
  • Thank you all...the problem lies in NSString as I am expecting from the very beginning. so I changed the type to UITextView and hide that and take the results from there. – Saty Feb 27 '13 at 13:46

1 Answers1

2

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);
Wextux
  • 752
  • 9
  • 18