黄学彪
2019-11-25 160785587667cc0d927f85e44c139ec9dde13a9e
ZigbeeApp/Home.Ios/AppDelegate.cs
old mode 100755 new mode 100644
File was renamed from ZigbeeApp/GateWay.Ios/AppDelegate.cs
@@ -1,21 +1,17 @@
using 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;
using Shared;
using Shared.Common;
using Shared.IOS.TBL;
using UIKit;
namespace GateWay.Ios
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
@@ -32,11 +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/");
            Shared.IOS.TBL.WXApi.RegisterApp("wx2ec8f53f6fa36e82", "https://hdlcontrol.com/ZigbeeApp/");
            DeviceTokenAction += (deviceToken) =>
            {
@@ -89,13 +85,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))
@@ -149,23 +145,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.
@@ -188,7 +189,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);
        }
@@ -198,8 +199,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();
@@ -218,7 +219,7 @@
        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);
@@ -246,7 +247,8 @@
                                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 {
                            catch
                            {
                                RespAction?.Invoke(null);
                            }
                            break;
@@ -274,7 +276,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();
@@ -294,7 +296,7 @@
                {
                    Width = width,
                    Height = height,
                    Margin = 10
                    Margin = 0
                }
            };
@@ -308,6 +310,4 @@
            return resultBytes;
        }
    }
}
}