From 8b9ce384b26c414db32f98e94e088f5334869c2d Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期三, 13 十一月 2019 15:36:28 +0800
Subject: [PATCH] 全部合并了代码,安卓和 IOS 都测试通过了

---
 ZigbeeApp/GateWay.Ios/AppDelegate.cs |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/ZigbeeApp/GateWay.Ios/AppDelegate.cs b/ZigbeeApp/GateWay.Ios/AppDelegate.cs
index 71e2a0f..21a52c7 100755
--- a/ZigbeeApp/GateWay.Ios/AppDelegate.cs
+++ b/ZigbeeApp/GateWay.Ios/AppDelegate.cs
@@ -23,13 +23,15 @@
             set;
         }
 
+        internal static UINavigationController rootViewController;
+
         public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
         {
-            base.FinishedLaunching(application, launchOptions);
+            //base.FinishedLaunching(application, launchOptions);
             Shared.Application.FontSize = 12;
             Window = new UIWindow(UIScreen.MainScreen.Bounds);
-            var root = new UINavigationController(new MainViewController()) { NavigationBarHidden = true };
-            Window.RootViewController = root;
+            rootViewController = new UINavigationController(new MainViewController()) { NavigationBarHidden = true };
+            Window.RootViewController = rootViewController;
             Window.MakeKeyAndVisible();
 
             DeviceTokenAction += (deviceToken) =>
@@ -211,4 +213,49 @@
     }
 }
 
- 
+namespace Shared
+{
+    public static class QRCode
+    {
+        static ZXing.Mobile.MobileBarcodeScanner scanner;
+        public static async System.Threading.Tasks.Task ScanQRcode(Action<string> action, string topText = "", string bottomText = "", string cancel = "Cancel")
+        {
+            if (scanner == null)
+            {
+                scanner = new ZXing.Mobile.MobileBarcodeScanner(GateWay.Ios.AppDelegate.rootViewController) { FlashButtonText = "", TopText = topText, BottomText = bottomText, CancelButtonText = cancel };
+            }
+
+            var result = await scanner.Scan();
+
+            if (result != null)
+                action?.Invoke(result.Text);
+            else
+                action?.Invoke(null);
+        }
+
+        public static byte[] BytesFromText(string text, int width = 300, int height = 300)
+        {
+            var barcodeWriter = new ZXing.Mobile.BarcodeWriter
+            {
+                Format = ZXing.BarcodeFormat.QR_CODE,
+                Options = new ZXing.Common.EncodingOptions
+                {
+                    Width = width,
+                    Height = height,
+                    Margin = 10
+                }
+            };
+
+            barcodeWriter.Renderer = new ZXing.Mobile.BitmapRenderer();
+            var uiImage = barcodeWriter.Write(text);
+            var data = uiImage.AsJPEG();
+
+            var resultBytes = new byte[data.Length];
+            System.Runtime.InteropServices.Marshal.Copy(data.Bytes, resultBytes, 0, resultBytes.Length);
+
+            return resultBytes;
+        }
+    }
+}
+
+

--
Gitblit v1.8.0