Commit 6e376241 authored by Felix Paul Kühne's avatar Felix Paul Kühne
Browse files

LAN server sync: fix previous commit

parent e7ad674a
...@@ -76,6 +76,11 @@ ...@@ -76,6 +76,11 @@
self.edgesForExtendedLayout = UIRectEdgeNone; self.edgesForExtendedLayout = UIRectEdgeNone;
} }
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewWillAppear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated
{ {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
...@@ -97,6 +102,12 @@ ...@@ -97,6 +102,12 @@
[self protocolSelectionChanged:nil]; [self protocolSelectionChanged:nil];
} }
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(ubiquitousKeyValueStoreDidChange:)
name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
object:[NSUbiquitousKeyValueStore defaultStore]];
NSUbiquitousKeyValueStore *ukvStore = [NSUbiquitousKeyValueStore defaultStore]; NSUbiquitousKeyValueStore *ukvStore = [NSUbiquitousKeyValueStore defaultStore];
[ukvStore synchronize]; [ukvStore synchronize];
_serverList = [NSMutableArray arrayWithArray:[ukvStore arrayForKey:kVLCStoredServerList]]; _serverList = [NSMutableArray arrayWithArray:[ukvStore arrayForKey:kVLCStoredServerList]];
...@@ -137,8 +148,16 @@ ...@@ -137,8 +148,16 @@
- (void)viewWillDisappear:(BOOL)animated - (void)viewWillDisappear:(BOOL)animated
{ {
[super viewWillDisappear:animated]; [super viewWillDisappear:animated];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSUbiquitousKeyValueStore *ukvStore = [NSUbiquitousKeyValueStore defaultStore];
[defaults setObject:_serverList forKey:kVLCStoredServerList]; [ukvStore setArray:_serverList forKey:kVLCStoredServerList];
[ukvStore synchronize];
}
- (void)ubiquitousKeyValueStoreDidChange:(NSNotification *)notification
{
/* TODO: don't blindly trust that the Cloud knows best */
_serverList = [NSMutableArray arrayWithArray:[[NSUbiquitousKeyValueStore defaultStore] arrayForKey:kVLCStoredServerList]];
[self.storedServersTableView reloadData];
} }
- (IBAction)connectToServer:(id)sender - (IBAction)connectToServer:(id)sender
......
...@@ -57,7 +57,6 @@ ...@@ -57,7 +57,6 @@
[super viewDidLoad]; [super viewDidLoad];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self [notificationCenter addObserver:self
selector:@selector(ubiquitousKeyValueStoreDidChange:) selector:@selector(ubiquitousKeyValueStoreDidChange:)
name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment