public override void DetectQRCode(bool autoHandleQR) { String returnValue = String.Empty; UIApplication.SharedApplication.InvokeOnMainThread (delegate { MobileBarcodeScanner scanner = new MobileBarcodeScanner(IPhoneServiceLocator.CurrentDelegate.MainUIViewController()); scanner.Scan().ContinueWith(t => { if (t.Result != null){ MediaQRContent resultQRContent = new MediaQRContent(t.Result.Text, ZxingToBarcode(t.Result.BarcodeFormat), getQRTypeFromCode(t.Result)); //SystemLogger.Log(SystemLogger.Module.PLATFORM, "QR CODE returnValue: " + resultQRContent); UIApplication.SharedApplication.InvokeOnMainThread (delegate { IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Unity.Media.onQRCodeDetected", resultQRContent); if(autoHandleQR) HandleQRCode(resultQRContent); }); } }); IPhoneServiceLocator.CurrentDelegate.SetMainUIViewControllerAsTopController(false); }); }
public abstract QRType HandleQRCode(MediaQRContent mediaQRContent);
public override QRType HandleQRCode(MediaQRContent mediaQRContent) { if (mediaQRContent != null && mediaQRContent.QRType!=null) { INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance ().GetService ("notify"); NSUrl param = new NSUrl (mediaQRContent.Text); switch (mediaQRContent.QRType) { case QRType.EMAIL_ADDRESS: if ((UIApplication.SharedApplication.CanOpenUrl (param) )&& (MFMailComposeViewController.CanSendMail)) { UIApplication.SharedApplication.OpenUrl (param); }else if (notificationService != null) notificationService.StartNotifyAlert ("Mail Alert", "Sending of mail messages is not enabled or supported on this device.", "OK"); break; case QRType.TEL: if (UIApplication.SharedApplication.CanOpenUrl (param)) { UIApplication.SharedApplication.OpenUrl (param); }else if (notificationService != null) notificationService.StartNotifyAlert ("Phone Alert", "Establishing voice calls is not enabled or supported on this device.", "OK"); break; case QRType.URI: if (UIApplication.SharedApplication.CanOpenUrl (param)) { UIApplication.SharedApplication.OpenUrl (param); }else if (notificationService != null) notificationService.StartNotifyAlert ("Browser Alert", "The requested URL could not be automatically opened.", "OK"); break; default: if (notificationService != null) notificationService.StartNotifyAlert ("QR Alert", "The QR Code " + mediaQRContent.QRType.ToString() + " cannot be processed automatically.", "OK"); break; } return mediaQRContent.QRType; } return QRType.TEXT; }