问题
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.
回答1:
Have you checked in DeviceLogs Window->Devices->View Device Logs? There must be crash logged.
来源:https://stackoverflow.com/questions/45296759/when-app-in-background-and-receiving-push-notification-tap-app-goes-crash