Когда приложение работает в фоновом режиме и получает push-уведомление, приложение выходит из строя

Я работаю над push-уведомлениями с Azure Notification Hub.

Я хочу запустить свое приложение из AppDelegate, где уведомление — это Tap.

Вот сценарий, как я могу открыть свое приложение.

Файл 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 и других сайтах, но у меня ничего не работает.

Я потратил на это 4 дня, но не добился успеха.

Любая помощь будет оценена по достоинству.


person Harshad Pansuriya    schedule 25.07.2017    source источник
comment
Вы поставили журналы также с точкой останова ....?   -  person Gourav Joshi    schedule 25.07.2017
comment
не могли бы вы поделиться, что такое журнал сбоев при попытке открыть.?   -  person Nitin Gohel    schedule 25.07.2017
comment
@GouravJoshi Я тестирую режим Release, поэтому точка останова не работает.   -  person Harshad Pansuriya    schedule 25.07.2017
comment
@NitinGohel, я тестирую режим выпуска, поэтому журнал сбоев не отображается.   -  person Harshad Pansuriya    schedule 25.07.2017
comment
проверьте после удаления кода запуска didFinish, чтобы установить новый корень, если обнаружено уведомление, которое не приведет к сбою. поэтому вам нужно переместить этот код в DidReceiveNotificationResponse или другой делегат уведомления.   -  person Nitin Gohel    schedule 25.07.2017
comment
вы имеете в виду, что если remoteNotification найдено, я хочу установить Root в этом методе DidReceiveNotificationResponse.   -  person Harshad Pansuriya    schedule 25.07.2017


Ответы (1)


Проверяли ли вы DeviceLogs Window->Devices->View Device Logs? Должен быть зарегистрирован сбой.

person Community    schedule 25.07.2017
comment
Используйте любой фреймворк, такой как Crashlytics, SplunkMint. Это действительно помогает регистрировать сбои на ходу. - person ; 25.07.2017
comment
Я развертываю в режиме выпуска, поэтому нет доступных вариантов. - person Harshad Pansuriya; 25.07.2017
comment
Просто для информации, разве вы не хотите получать отчеты о сбоях от реальных пользователей приложения? - person ; 25.07.2017
comment
Спасибо за информацию, но для этого есть Xamarin Profiler. - person Harshad Pansuriya; 25.07.2017