ios - 在设置包中的设置更改时收到通知(在 Xamarin iOS 中)
问题描述
我希望我的应用程序在设置包中的一项设置发生更改时收到通知。或者如果这不可能,任何改变(然后我会检查它是否是那个特定的设置)。
我将如何在 Xamarin iOS 中实现这一点?
解决方案
只需将 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);
}
推荐阅读
- javascript - 数据表日期时间格式排序问题
- composer-php - Composer 不拉包 v10.4.21
- azure - 如何在 Azure 运行管道菜单中添加默认变量
- conda - conda-forge 安全吗?
- django - 如何在 djhtml 中配置 tabwidth?
- python - 使用 camelot-py (lattice) 提取 PDF 表:split_text 不起作用
- android - 如何修复他的错误异常:Gradle 任务 assembleDebug 失败,退出代码为 1
- angular - 离子服务不适用于“应用内浏览器”插件
- python - Python程序对矩阵的每一行和每一列求和
- javascript - 如何通过具有firebase功能的FTP下载文件?