1
私はPCLプロジェクトを持っており、(タスクが単純な文字列を表示し終えたら)簡単な通知を表示する必要があります。Xamarinフォームのローカル通知のためのFoundation.ModelNotImplementedException
Window.RootViewController.PresentViewController(okayAlertController, true, null);
例外がスローされます:Foundation.ModelNotImplementedException:型「Foundation.ModelNotImplementedException」の例外がスローされたiOSのプロジェクトでは、私はとReceivedLocalNotificationで通知を表示しようとします。
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null
);
app.RegisterUserNotificationSettings(notificationSettings);
// check for a notification
if (options != null)
{
// check for a local notification
if (options.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey))
{
var localNotification = options[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification;
if (localNotification != null)
{
UIAlertController okayAlertController = UIAlertController.Create(localNotification.AlertAction, localNotification.AlertBody, UIAlertControllerStyle.Alert);
okayAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
Window.RootViewController.PresentViewController(okayAlertController, true, null);
UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;
}
}
}
}
base.FinishedLaunching(app, options);
}
public override void ReceivedLocalNotification(UIApplication application, UILocalNotification notification)
{
// show an alert
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;
}
}
そしてNotificationService_iOS.cs:ここでは、コードです
public class NotificationService_iOS : INotificationService
{
public void Notify(string title, string text)
{
var notification = new UILocalNotification();
notification.FireDate = NSDate.FromTimeIntervalSinceNow(0); // Fire now
notification.AlertAction = title;
notification.AlertBody = text;
notification.ApplicationIconBadgeNumber = 1;
notification.SoundName = UILocalNotification.DefaultSoundName;
UIApplication.SharedApplication.ScheduleLocalNotification(notification);
}
}
私はまったく同じエラーを取得しています。ローカル通知に関するXamarinチュートリアルのght – Mike