Xamarin 形成 iOS 本地通知按钮
Posted
技术标签:
【中文标题】Xamarin 形成 iOS 本地通知按钮【英文标题】:Xamarin forms iOS local notification buttons 【发布时间】:2017-10-19 12:59:21 【问题描述】:我需要在 ios 的本地通知中显示操作按钮。我收到通知,但没有操作按钮。你能指导我我做错了什么吗? 这是我的代码:
var category = new UIMutableUserNotificationCategory();
var okAction = new UIMutableUserNotificationAction
Identifier = "ok",
Destructive = false,
Title = "OK",
ActivationMode = UIUserNotificationActivationMode.Background,
AuthenticationRequired = false
;
var delayAction = new UIMutableUserNotificationAction
Identifier = "delay",
Destructive = false,
Title = "Отложить",
ActivationMode = UIUserNotificationActivationMode.Background,
AuthenticationRequired = false
;
var categoryIdentifier = "pills.category";
category.Identifier = categoryIdentifier;
category.SetActions(new UIUserNotificationAction[] delayAction, okAction , UIUserNotificationActionContext.Minimal);
category.SetActions(new UIUserNotificationAction[] delayAction, okAction , UIUserNotificationActionContext.Default);
var categories = new NSSet(new NSObject[] category);
var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, categories
);
UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings);
var next = new TimeSpan(start.Ticks);
var count = Math.Round(24.0 / interval.TotalHours);
for (int i = 0; i < count; i++)
var notification = new UILocalNotification
AlertAction = title,
AlertBody = text,
SoundName = UILocalNotification.DefaultSoundName,
ApplicationIconBadgeNumber = 0,
FireDate = NSDate.FromTimeIntervalSinceNow(next.TotalSeconds),
RepeatInterval = NSCalendarUnit.Day,
Category = categoryIdentifier
;
UIApplication.SharedApplication.ScheduleLocalNotification(notification);
next = next.Add(interval);
附:我正在使用 iOS 11 模拟器。
【问题讨论】:
【参考方案1】:您需要向下滑动才能看到按钮。
以下动图演示如何在Background
和Lock Screen
中操作
【讨论】:
以上是关于Xamarin 形成 iOS 本地通知按钮的主要内容,如果未能解决你的问题,请参考以下文章
用户关闭应用程序时如何处理用户在 Xamarin iOS 上单击本地通知?
当本地通知在特定时间触发时如何在 xamarin ios 中播放警报音