Forum Xamarin.iOS

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

zBar binding and sample project

RickGrossRickGross USMember, Beta

Would anyone be so kind as to point me at a working zBar binding and a small sample project?

Thanks very much,
Rick

Posts

  • JoseCarlosToledoMuozJoseCarlosToledoMuoz ESMember ✭✭
    edited December 2012
  • RickGrossRickGross USMember, Beta

    Thanks for the link - can't get the project to compile and there is no sample of how to use the binding. Any other ideas would be much appreciated.

    Rick

  • RickGrossRickGross USMember, Beta

    OK - got the binding to compile and installed in my project - now I need some sort of sample on HOW to use it... Any samples out there?

  • RickGrossRickGross USMember, Beta

    Here is what I've come up with for some sample code:

    `CameraPicker3 = new ZBarReaderViewController();

                CameraPicker3.Scanner.SetSymbolOption(0, ZBarConfig.Enabled, 0);
                CameraPicker3.Scanner.SetSymbolOption(ZBarSymbolType.QRCode, ZBarConfig.Enabled, 1);
                CameraPicker3.Scanner.SetSymbolOption(ZBarSymbolType.EAN13, ZBarConfig.Enabled, 1);
                CameraPicker3.Scanner.SetSymbolOption(ZBarSymbolType.EAN8, ZBarConfig.Enabled, 1);
    
                CameraPicker3.ReaderDelegate = new ZbarPickerDelegate(mvController);
    
                this.mvController.PresentModalViewController(CameraPicker3, true);`
    

    And:

    `public class ZbarPickerDelegate : ZBarReaderDelegate//UIImagePickerControllerDelegate
    {
    // MainViewController _mvc;
    MainViewController _mvc;
    AppDelegate appDelegate = (AppDelegate) UIApplication.SharedApplication.Delegate;

            public ZbarPickerDelegate(MainViewController mvc):base()
            {
                try{
                    _mvc = mvc;
    
                }
                catch(Exception ex)
                {
                    Log.LogError("ImagePickerDelegate", ex);
                }
    
            }
    
            public override void FinishedPickingMedia (UIImagePickerController picker, NSDictionary info)
            {
                try
                {
                    string bresult = "";
                    var scanKey = new NSString("ZBarReaderControllerResults");
                    if(info.ContainsKey(scanKey))
                    {
                        CameraPicker3.DismissViewController(false, null);
    
                        SystemSound.FromFile ("Scanner/beep.wav").PlayAlertSound ();
    
                        var item = info.ObjectForKey(scanKey);
                        ZBarSymbolSet symbolSet = (ZBarSymbolSet)item;
                        foreach(var it in symbolSet)
                        {
                            bresult = it.Data.ToString();
                            break;
                        }
    
                        switch(bresult.Length)
                        {
                        case 9:
                            bresult = bresult.Substring(1);
                            break;
                        case 13:
                            bresult = bresult.Substring(1);
                            break;
                        }
    
    
                        appDelegate.ReturnFromScan(bresult);
                    }
    
    
                }
                catch(Exception ex)
                {
                    Log.LogError("FinishedPickingMedia",ex);
                }
            }
        }`
    

    Sorry for the formatting - can't quite figure out this editor...

    Regards,
    Rick

Sign In or Register to comment.