0

I would like my app to be notified of a change in one of the settings in the settings bundle. Or if that's not possible, of any change (and I will then check if it was that specific setting).

How would I achieve that in Xamarin iOS?

It seems like one of those options is addressed in these answers one and two. But I can't figure out how to do that in Xamarin/C#.

ispiro
  • 26,556
  • 38
  • 136
  • 291

1 Answers1

1

Just translate the Objective-C code to C# and if you read the document here, you will find there are some examples:

// Lambda style

NSNotificationCenter.DefaultCenter.AddObserver(

    NSValueTransformer.UserDefaultsDidChangeNotification, (notification) => { Console.WriteLine("Received the notification NSValueTransformer", notification); }

);

//Method style

void Callback(NSNotification notification)
{
    Console.WriteLine("Received a notification NSValueTransformer", notification);
}

void Setup()
{
    NSNotificationCenter.DefaultCenter.AddObserver(NSValueTransformer.UserDefaultsDidChangeNotification, Callback);
}

Refer: userdefaultsdidchangenotification

nevermore
  • 15,432
  • 1
  • 12
  • 30
  • Thanks. But is there a way to find which setting was it that was changed? – ispiro Oct 07 '19 at 18:20
  • @ispiro Can you please mark this answer and I saw you opened an new issue about this new problem, I have added my answer there. Thanks. – nevermore Oct 08 '19 at 03:21