简体   繁体   中英

When App in Background and receiving push notification tap App goes crash

I am working on Push Notification with Azure Notification Hub.

I want to start my app from AppDelegate where the Notification is Tap.

Here is the Scenario, How I can open my App.

AppDelegate.cs file

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 file

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
    }

I have tried all possible scenario which i found on google and So and other site but nothing is working for me.

I spent 4 days on this but not get success.

Any Help Will be Appreciated.

Have you checked in DeviceLogs Window->Devices->View Device Logs ? There must be crash logged.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM