在设置包中的设置更改时收到通知(在 Xamarin iOS 中) [英] Be notified of change in a setting in Settings Bundle (in Xamarin iOS)
问题描述
我希望我的应用在设置包中的一项设置发生更改时收到通知.或者,如果这不可能,则进行任何更改(然后我会检查是否是该特定设置).
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).
我将如何在 Xamarin iOS 中实现这一目标?
How would I achieve that in Xamarin iOS?
似乎在这些答案one和两个.但我不知道如何在 Xamarin/C# 中做到这一点.
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#.
推荐答案
只需将 Objective-C 代码翻译成 C#,如果你阅读了 文档在这里,你会发现有一些例子:
Just translate the Objective-C code to C# and if you read the document here, you will find there are some examples:
//Lambda 风格
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);
}
参考:userdefaultsdidchangenotification
这篇关于在设置包中的设置更改时收到通知(在 Xamarin iOS 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!