我希望我的应用程序收到有关设置包中某个设置更改的通知。或者,如果不可能,则进行任何更改(然后我将检查是否是该特定设置(。
我将如何在 Xamarin iOS 中实现这一目标?
似乎这些选项之一在这些答案一和二中得到了解决。但是我不知道如何在Xamarin/C #中做到这一点。
只需将 Objective-C 代码转换为 C#,如果您阅读此处的文档,您会发现有一些示例:
拉姆达风格
NSNotificationCenter.DefaultCenter.AddObserver(
NSValueTransformer.UserDefaultsDidChangeNotification, (notification) => { Console.WriteLine("Received the notification NSValueTransformer", notification); }
);
方法样式
void Callback(NSNotification notification)
{
Console.WriteLine("Received a notification NSValueTransformer", notification);
}
void Setup()
{
NSNotificationCenter.DefaultCenter.AddObserver(NSValueTransformer.UserDefaultsDidChangeNotification, Callback);
}
参考: 用户默认更改通知