2
我想向用戶顯示通知,但標題始終爲空。問題是notification.AlertAction在顯示通知之前爲空。本地通知AlertAction在Xamarin iOS中始終爲空
public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
{
// notification.AlertAction is null!!! while notification.AlertBody is correct
UIAlertController okayAlertController = UIAlertController.Create(notification.AlertAction, notification.AlertBody, UIAlertControllerStyle.Alert);
okayAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
Window.RootViewController.PresentViewController(okayAlertController, true, null);
UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
}
,我同時設置notification.AlertAction和notification.AlertBody:
public class NotificationService_iOS : INotificationService
{
public void Notify(string title, string text)
{
var notification = new UILocalNotification();
notification.FireDate = NSDate.FromTimeIntervalSinceNow(0);
notification.AlertAction = title;
notification.AlertBody = text;
notification.ApplicationIconBadgeNumber = 1;
notification.SoundName = UILocalNotification.DefaultSoundName;
UIApplication.SharedApplication.ScheduleLocalNotification(notification);
}
}