如何以编程方式将Xamrin MAC应用程序置于前台?

问题描述 投票:0回答:1

如何通过单击本地通知以编程方式将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

macos xamarin xamarin.forms xamarin-studio xamarin.mac
1个回答
0
投票

您可以使用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);
};
© www.soinside.com 2019 - 2024. All rights reserved.