Когда приложение в фоновом режиме и получение push-уведомления нажмите приложение выходит из строя
Я работаю над push-уведомлениями в Azure Notification Hub.
Я хочу запустить свое приложение из 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, и на других сайтах, но у меня ничего не работает.
Я потратил 4 дня на это, но не добился успеха.
Любая помощь будет оценена.
1 ответ
Вы проверили в окне DeviceLogs- > Устройства-> Просмотр журналов устройства? Там должно быть зарегистрировано падение.