В проекте Xamarin.iOS я перехватываю push-уведомление и хочу изменить его перед тем, как представить его пользователю в соответствии с некоторыми условиями, которые доступны (сохраненные настройки) в проекте iOS. Как передать данные из проекта iOS в расширение службы уведомлений и, возможно, наоборот? Или, точнее, как я могу получить доступ к пользовательским настройкам из проекта Xamarin.Forms в проекте расширения службы уведомлений iOS?
Меня больше всего интересует доступ к пользовательским настройкам, сохраненным с помощью Xamarin.Essentials
Это код шаблона для расширения службы уведомлений:
namespace NotifServiceExtension
{
[Register("NotificationService")]
public class NotificationService : UNNotificationServiceExtension
{
Action<UNNotificationContent> ContentHandler { get; set; }
UNMutableNotificationContent BestAttemptContent { get; set; }
protected NotificationService(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
public override void DidReceiveNotificationRequest(UNNotificationRequest request, Action<UNNotificationContent> contentHandler)
{
ContentHandler = contentHandler;
BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy();
// Modify the notification content here...
var region = Preferences.Get("region_key", "error"); // I cannot access preferences this way
BestAttemptContent.Title = string.Format("{0}[modified]", BestAttemptContent.Title);
ContentHandler(BestAttemptContent);
}
public override void TimeWillExpire()
{
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
ContentHandler(BestAttemptContent);
}
}
}