如何知道用户何时更改设置包 [英] How to know when user made change to settings bundle

查看:57
本文介绍了如何知道用户何时更改设置包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我让用户在iphone的设置区域中更改其设置.在下一次网络同步期间,我想将用户更改发送到服务器.但是只有进行了更改.

I let the user make changes to their settings in the settings area of the iphone. During the next network sync i'd like to send the user changes to the server. But only if the changes are made.

但是我怎么知道用户何时在设置区域中进行了更改?

But how do I know when the user has made a change within the settings area?

如果可以的话,我想避免始终发送信息(无论是否更改),或者先从服务器获取信息,然后再更新(如果与用户默认设置不同的话)的选项.

If I can, I'd like to avoid an option of always sending the information regardless if changed or not or getting the info from the server first and updating if different from the user defaults.

是否有解决该问题的好方法? 谢谢您的帮助!

Is there a nice and elegant way of resolving this problem? Thank you for your help!

一个星期后,没有答案... 这个问题太难了还是根本没有任何意义?

A week later and no answers... Is this question too hard or it doesn't make any sense at all?

推荐答案

啊,愚蠢的我!在这里,我们以一种优雅的方式进行.在XCode的Apple文档中搜索AppPrefs,它将显示一个示例应用程序,该应用程序完全可以执行您想要的操作.只需编译并运行!它利用了 NSUserDefaultsDidChangeNotification .

Ah silly me! Here we go with an elegant way. Search for AppPrefs in the Apple Documentation within XCode and it'll show an example app which does exactly what you want to do. Just compile and run! It makes use of the NSUserDefaultsDidChangeNotification.

这是用于注册观察者的代码:

This is the code being used to register an observer:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(defaultsChanged:)
                                             name:NSUserDefaultsDidChangeNotification
                                           object:nil];


旧答案:

看起来好像您可以从NSUserDefaults中获得修改日期.到目前为止,我只能想到这种方式:

It doesn't look like as if you could get a modification date out of the NSUserDefaults. So far I only can think of this way:

NSUserDefaults *previousDefaults = [someInstance previousUserDefaults];
NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];

if([previousDefaults isEqualToDictionary:currentDefaults]) 
{
    [someOtherInstance sendModifiedUserDefaultsToServerWithDefaults:currentDefaults];
    [yetAnotherInstance saveModified]
}

您必须在首次启动该应用程序时将用户默认值自己保存为字典到磁盘:您的默认值.然后,每次打开应用程序时,您都要比较这两个词典.如果他们

You have to save the user defaults yourself as dictionary to disk when the app is launched the first time: your default values. Then, everytime the app is opened you compare those two dictionaries. If they

这篇关于如何知道用户何时更改设置包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆