Last active
December 23, 2015 22:59
-
-
Save cdeutsch/6707164 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public override bool FinishedLaunching (UIApplication app, NSDictionary options) | |
{ | |
JsBridge.EnableJsBridge(); | |
window = new UIWindow (UIScreen.MainScreen.Bounds); | |
// get useragent | |
UIWebView agentWebView = new UIWebView (); | |
var userAgent = agentWebView.EvaluateJavascript ("navigator.userAgent"); | |
agentWebView = null; | |
userAgent += " XamarinBarcodeSampleApp"; | |
// set default useragent | |
NSDictionary dictionary = NSDictionary.FromObjectAndKey(NSObject.FromObject(userAgent), NSObject.FromObject("UserAgent")); | |
NSUserDefaults.StandardUserDefaults.RegisterDefaults(dictionary); | |
viewController = new Xamarin_iOS_BarcodeSampleViewController (); | |
window.RootViewController = viewController; | |
window.MakeKeyAndVisible (); | |
viewController.MainWebView.LoadRequest(new NSUrlRequest(new NSUrl("http://xamarinbarcodesample.apphb.com/"))); | |
// listen for the event triggered by the browser. | |
viewController.MainWebView.AddEventListener( "scanBarcode", delegate(FireEventData arg) { | |
// show a native action sheet | |
BeginInvokeOnMainThread (delegate { | |
//NOTE: On Android you MUST pass a Context into the Constructor! | |
var scanningOptions = new ZXing.Mobile.MobileBarcodeScanningOptions(); | |
scanningOptions.PossibleFormats = new List<ZXing.BarcodeFormat>() { | |
ZXing.BarcodeFormat.All_1D | |
}; | |
scanningOptions.TryInverted = true; | |
scanningOptions.TryHarder = true; | |
scanningOptions.AutoRotate = false; | |
var scanner = new ZXing.Mobile.MobileBarcodeScanner(); | |
scanner.TopText = "Hold camera up to barcode to scan"; | |
scanner.BottomText = "Barcode will automatically scan"; | |
scanner.Scan(scanningOptions).ContinueWith(t => { | |
if (t.Result != null) { | |
//Console.WriteLine("Scanned Barcode: " + t.Result.Text); | |
// pass barcode back to browser. | |
viewController.MainWebView.FireEvent( "scanComplete", new { | |
code = t.Result.Text | |
}); | |
} | |
}); | |
}); | |
}); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment