如何通过单击本地通知以编程方式将Xamarin MAC应用程序置于前台?我该如何实现?我已经为本地通知编写了以下代码。在单击该本地通知时,我希望前台显示我的应用程序。
NSUserNotificationCenter center = NSUserNotificationCenter.DefaultUserNotificationCenter;
NSUserNotification notification = new NSUserNotification();
notification.Title = title;
notification.Subtitle = content;
notification.InformativeText = "TEST";
notification.SoundName = NSUserNotification.NSUserNotificationDefaultSoundName;
notification.DeliveryDate = NSDate.FromTimeIntervalSinceNow(1);
center.ScheduleNotification(notification);
center.DidDeliverNotification += (s, e) =>
{
Console.WriteLine("Notification Delivered");
};
center.DidActivateNotification += (s, e) =>
{
Console.WriteLine("Notification Touched");
};
谢谢你,Vivek
您可以使用NSWorkspace.SharedWorkspace.LaunchApp
“启动”您的应用程序,该应用程序是否已在运行中都没有关系,您可以使用NSWorkspaceLaunchOptions.HideOthers
仅显示该应用程序的最后一个活动窗口。
center.DidActivateNotification += (s, e) =>
{
Console.WriteLine("Notification Touched");
NSWorkspace.SharedWorkspace.LaunchApp(NSBundle.MainBundle.BundleIdentifier, NSWorkspaceLaunchOptions.HideOthers, new NSAppleEventDescriptor(), IntPtr.Zero);
};