我正在使用 Azure 通知中心处理推送通知。
我想从通知为 Tap 的 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天时间,但没有成功。
任何帮助将不胜感激。