From f8b647c263f068babb8efcc19ff4e74026a4bd28 Mon Sep 17 00:00:00 2001 From: WJC <wjc@hdlchina.com.cn> Date: 星期二, 03 十二月 2019 10:44:28 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev-tzy' into dev-wjc --- ZigbeeApp/Home.Ios/AppDelegate.cs | 114 +++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 83 insertions(+), 31 deletions(-) diff --git a/ZigbeeApp/GateWay.Ios/AppDelegate.cs b/ZigbeeApp/Home.Ios/AppDelegate.cs similarity index 74% rename from ZigbeeApp/GateWay.Ios/AppDelegate.cs rename to ZigbeeApp/Home.Ios/AppDelegate.cs index c22056e..d9396e2 100644 --- a/ZigbeeApp/GateWay.Ios/AppDelegate.cs +++ b/ZigbeeApp/Home.Ios/AppDelegate.cs @@ -1,19 +1,17 @@ +锘縰sing System; using Foundation; -using UIKit; -using Shared; -using System; -using ObjCRuntime; -using UserNotifications; -using Shared.Common; using Microsoft.AppCenter; using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; -namespace GateWay.Ios +using Shared; +using Shared.Common; +using Shared.IOS.TBL; +using UIKit; + +namespace Home.IOS { - // The UIApplicationDelegate for the application. This class is responsible for launching the - // User Interface of the application, as well as listening (and optionally responding) to application events from iOS. [Register("AppDelegate")] - public class AppDelegate : BaseApplicationDelegate + public class AppDelegate : BaseApplicationDelegate { public static bool haveToSignOut = false; // class-level declarations @@ -30,9 +28,11 @@ //base.FinishedLaunching(application, launchOptions); Shared.Application.FontSize = 12; Window = new UIWindow(UIScreen.MainScreen.Bounds); - rootViewController = new UINavigationController(new MainViewController()) { NavigationBarHidden = true }; + rootViewController = new UINavigationController(new GateWay.Ios.MainViewController()) { NavigationBarHidden = true }; Window.RootViewController = rootViewController; Window.MakeKeyAndVisible(); + + Shared.IOS.TBL.WXApi.RegisterApp("wx2ec8f53f6fa36e82", "https://hdlcontrol.com/ZigbeeApp/"); DeviceTokenAction += (deviceToken) => { @@ -86,13 +86,13 @@ } public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler) { - if (userInfo==null) + if (userInfo == null) { return; } Console.WriteLine(userInfo); - if(application.ApplicationState==UIApplicationState.Active || application.ApplicationState==UIApplicationState.Background) + if (application.ApplicationState == UIApplicationState.Active || application.ApplicationState == UIApplicationState.Background) { NSString key_hiddenJson = new NSString("HiddenJson"); if (userInfo.ContainsKey(key_hiddenJson)) @@ -146,23 +146,28 @@ } } } - + } completionHandler(UIBackgroundFetchResult.NewData); } - public override void ReceivedRemoteNotification (UIApplication application, NSDictionary userInfo) + public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo) { Console.WriteLine(userInfo); - if (application.ApplicationState == UIApplicationState.Active) { - System.Console.WriteLine ("ReceivedRemoteNotification1"); - } else if (application.ApplicationState == UIApplicationState.Background) { - System.Console.WriteLine ("ReceivedRemoteNotification2"); - } else if (application.ApplicationState == UIApplicationState.Inactive) { - System.Console.WriteLine ("ReceivedRemoteNotification3"); - } + if (application.ApplicationState == UIApplicationState.Active) + { + System.Console.WriteLine("ReceivedRemoteNotification1"); + } + else if (application.ApplicationState == UIApplicationState.Background) + { + System.Console.WriteLine("ReceivedRemoteNotification2"); + } + else if (application.ApplicationState == UIApplicationState.Inactive) + { + System.Console.WriteLine("ReceivedRemoteNotification3"); + } } - + public override void OnResignActivation(UIApplication application) { // Invoked when the application is about to move from active to inactive state. @@ -185,7 +190,7 @@ { // Called as part of the transiton from background to active state. // Here you can undo many of the changes made on entering the background. - System.Console.WriteLine ("WillEnterForeground"); + System.Console.WriteLine("WillEnterForeground"); UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; base.WillEnterForeground(application); } @@ -195,8 +200,8 @@ // Restart any tasks that were paused (or not yet started) while the application was inactive. // If the application was previously in the background, optionally refresh the user interface. base.OnActivated(application); - - if(haveToSignOut==true) + + if (haveToSignOut == true) { //寮哄埗涓嬬嚎 CommonPage.Instance.SingOut(); @@ -211,6 +216,55 @@ // Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground. base.WillTerminate(application); } + + public static Action<string> RespAction; + public static void WXLogin() + { + + + var req = new SendAuthReq { Scope = "snsapi_userinfo", State = "ZigbeeApp", OpenID = "0c806938e2413ce73eef92cc3" }; + WXApi.SendAuthReq(req, rootViewController, null, null); + + } + + MyWXApiDelegate myWXApiDelegate = new MyWXApiDelegate { }; + + class MyWXApiDelegate : WXApiDelegate + { + public override void OnReq(BaseReq req) + { + + } + public override void OnResp(BaseResp resp) + { + if (resp is SendAuthResp) + { + var sendAuthResp = resp as SendAuthResp; + switch (sendAuthResp.ErrCode) + { + case 0: + try + { + var result = new System.Net.WebClient { }.DownloadString($"https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx2ec8f53f6fa36e82&secret=a08585cd6ff2ce64570b9e7e6525dd8e&code={((SendAuthResp)resp).Code}&grant_type=authorization_code"); + RespAction?.Invoke(result); + } + catch + { + RespAction?.Invoke(null); + } + break; + default: + RespAction?.Invoke(null); + break; + } + + } + } + } + public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler) + { + return WXApi.HandleOpenUniversalLink(userActivity, myWXApiDelegate); + } } } @@ -223,7 +277,7 @@ { if (scanner == null) { - scanner = new ZXing.Mobile.MobileBarcodeScanner(GateWay.Ios.AppDelegate.rootViewController) { FlashButtonText = "", TopText = topText, BottomText = bottomText, CancelButtonText = cancel }; + scanner = new ZXing.Mobile.MobileBarcodeScanner(Home.IOS.AppDelegate.rootViewController) { FlashButtonText = "", TopText = topText, BottomText = bottomText, CancelButtonText = cancel }; } var result = await scanner.Scan(); @@ -243,7 +297,7 @@ { Width = width, Height = height, - Margin = 10 + Margin = 0 } }; @@ -257,6 +311,4 @@ return resultBytes; } } -} - - +} \ No newline at end of file -- Gitblit v1.8.0