我正在创建一个iOS应用程序,可以管理用户并登录它们.
我想保留每个用户的用户数据设置,但我不确定每个用户保存此设置的最佳方法是什么.
我应该将数据保存到xml文件,还是NSUserDefaults,甚至将它们保存到我的Parse Cloud数据库中?
我只想在加载视图时保存用户属性列表,但我必须考虑到我的应用程序必须为当前用户加载正确的参数.
例如:
用户:Peter trackingSwitchEnabled:是的
用户:Molly trackingSwitchEnabled:没有
用户:Paul trackingSwitchEnabled:是的
我认为应该在这里:
-(void) viewWillDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver:self];
}
Run Code Online (Sandbox Code Playgroud)
或者也许在-dealloc.
这两个听起来都很奇怪所以我不完全确定它.
首先,在我的AppDelegate中,我通过Parse收听远程通知
- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
NSString * urlToGo = [userInfo objectForKey:@"url"];
NSLog (@"Recibo notificación con paremetro url: %@", urlToGo);
NSNotification *note = [NSNotification
notificationWithName:PUSH_NOTIFICATION
object:self
userInfo:userInfo];
[[NSNotificationCenter defaultCenter] postNotification:note];
}
Run Code Online (Sandbox Code Playgroud)
在myViewController中 - (void)viewDidLoad {[super viewDidLoad];
_lastMenuSelected=menu1;
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
[center addObserverForName:PUSH_NOTIFICATION
object:nil
queue:mainQueue
usingBlock:^(NSNotification *note) {
// Save in property to …Run Code Online (Sandbox Code Playgroud)