簡體   English   中英

當應用程序在后台接收推送通知時,應用程序崩潰

[英]When App in Background and receiving push notification tap App goes crash

我正在使用Azure Notification Hub進行Push Notification。

我想從“通知”為“輕按”的AppDelegate啟動我的應用。

這是方案,如何打開我的應用程序。

AppDelegate.cs文件

public class AppDelegate : UIApplicationDelegate
    {
        // class-level declarations
        private SBNotificationHub Hub { get; set; }

        public bool appIsStarting = false;

        public SlideoutNavigationController Menu { get; private set; }


        public override UIWindow Window
        {
            get;
            set;
        }

        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            if (launchOptions != null)
            {
                // check for a remote notification
                if (launchOptions.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                {

                    NSDictionary remoteNotification = launchOptions[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                    if (remoteNotification != null)
                    {
                        Window = new UIWindow(UIScreen.MainScreen.Bounds);
                        Menu = new SlideoutNavigationController();

                        var storyboard = UIStoryboard.FromName("Main", null);
                        var webController = storyboard.InstantiateViewController("DashBoardViewController") as DashBoardViewController;

                        Menu.MainViewController = new MainNavigationController(webController, Menu);
                        Menu.MenuViewController = new MenuNavigationController(new DummyControllerLeft(), Menu) { NavigationBarHidden = false };

                        Window.RootViewController = Menu;
                        Window.MakeKeyAndVisible();
                    }
                }
                ReceivedRemoteNotification(application, launchOptions);

            }
            else
            {

                UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false);
                UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
            }

            UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();

            return true;
        }
}

UserNotificationCenterDelegate.cs文件

class UserNotificationCenterDelegate : UNUserNotificationCenterDelegate
    {

        public SlideoutNavigationController Menu { get; private set; }



        #region Constructors
        public UserNotificationCenterDelegate()
        {
        }
        #endregion

        #region Override Methods
        public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
        {
            // Do something with the notification
            Console.WriteLine("Active Notification: {0}", notification);


            // Tell system to display the notification anyway or use
            // `None` to say we have handled the display locally.
            completionHandler(UNNotificationPresentationOptions.Alert);
        }

        public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
        {
            base.DidReceiveNotificationResponse(center, response, completionHandler);
        }

        #endregion
    }

我已經嘗試了所有可能的情況,這些情況我在google和So及其他網站上找到,但沒有任何用處。

我花了四天時間,但沒有成功。

任何幫助將不勝感激。

您是否已在DeviceLogs 窗口-> Devices-> View Device Logs中簽入過? 必須記錄崩潰。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM