ページ「Xamarin.MacでNLogを使う」と「Xamarin.Macで通知センターを使用する」の間の差分
(ページ間の差分)
ナビゲーションに移動
検索に移動
imported>Administrator 細 (Administrator がページ「Xamarin.Mac/NLogを使う」を「Xamarin.MacでNLogを使う」に移動しました) |
imported>Administrator |
||
1行目: | 1行目: | ||
− | |||
− | + | [[macOS]]の標準設定では3分以内に同じ通知を繰り返し送信するとポップアップ表示されない(右上の通知アイコンをクリックすると一覧にはいる)。 | |
− | [[ | + | これを知らず下記の[[ソースコード]]のAPIの呼び方が間違っていてポップアップ通知がされない[[バグ]]だと思って[[ググって]]しまった。 |
+ | <source lang="csharp"> | ||
+ | var userNotifycationCenter = NSUserNotificationCenter.DefaultUserNotificationCenter; | ||
− | + | // 通知がクリックされたとき | |
+ | userNotifycationCenter.DidActivateNotification += (sender, e) => { | ||
+ | Console.WriteLine("DidActivateNotification: " + e.Notification); | ||
+ | }; | ||
− | == | + | // 通知されたとき |
− | + | userNotifycationCenter.DidDeliverNotification += (sender, e) => { | |
+ | Console.WriteLine("DidDeliverNotification"); | ||
+ | }; | ||
− | + | // create | |
− | + | var userNotification = new NSUserNotification(); | |
− | + | userNotification.Title = "タイトル"; | |
− | + | userNotification.Subtitle = "サブタイトル"; | |
− | + | userNotification.InformativeText = "本文"; | |
− | + | userNotification.UserInfo = NSDictionary.FromObjectsAndKeys(new[] { "val" }, new[] { "key" }); | |
− | |||
− | |||
− | + | // 10秒後に通知 | |
+ | userNotification.DeliveryDate = NSDate.Now.AddSeconds(10); | ||
− | + | // 通知実行 | |
− | + | //userNotifycationCenter.DeliverNotification(un); | |
− | + | userNotifycationCenter.ScheduleNotification(userNotification); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</source> | </source> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | [[category:Xamarin.Mac | + | [[category: Xamarin.Mac]] |
− |
2017年11月17日 (金) 02:15時点における最新版
macOSの標準設定では3分以内に同じ通知を繰り返し送信するとポップアップ表示されない(右上の通知アイコンをクリックすると一覧にはいる)。 これを知らず下記のソースコードのAPIの呼び方が間違っていてポップアップ通知がされないバグだと思ってググってしまった。
var userNotifycationCenter = NSUserNotificationCenter.DefaultUserNotificationCenter;
// 通知がクリックされたとき
userNotifycationCenter.DidActivateNotification += (sender, e) => {
Console.WriteLine("DidActivateNotification: " + e.Notification);
};
// 通知されたとき
userNotifycationCenter.DidDeliverNotification += (sender, e) => {
Console.WriteLine("DidDeliverNotification");
};
// create
var userNotification = new NSUserNotification();
userNotification.Title = "タイトル";
userNotification.Subtitle = "サブタイトル";
userNotification.InformativeText = "本文";
userNotification.UserInfo = NSDictionary.FromObjectsAndKeys(new[] { "val" }, new[] { "key" });
// 10秒後に通知
userNotification.DeliveryDate = NSDate.Now.AddSeconds(10);
// 通知実行
//userNotifycationCenter.DeliverNotification(un);
userNotifycationCenter.ScheduleNotification(userNotification);