Pārlūkot izejas kodu

LAN server sync: fix previous commit

Felix Paul Kühne 9 gadi atpakaļ
vecāks
revīzija
6e37624186

+ 21 - 2
Sources/LocalNetworkConnectivity/VLCNetworkLoginViewController.m

@@ -76,6 +76,11 @@
     self.edgesForExtendedLayout = UIRectEdgeNone;
 }
 
+- (void)dealloc
+{
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
+}
+
 - (void)viewWillAppear:(BOOL)animated
 {
     [super viewWillAppear:animated];
@@ -97,6 +102,12 @@
         [self protocolSelectionChanged:nil];
     }
 
+    NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+    [notificationCenter addObserver:self
+                           selector:@selector(ubiquitousKeyValueStoreDidChange:)
+                               name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
+                             object:[NSUbiquitousKeyValueStore defaultStore]];
+
     NSUbiquitousKeyValueStore *ukvStore = [NSUbiquitousKeyValueStore defaultStore];
     [ukvStore synchronize];
     _serverList = [NSMutableArray arrayWithArray:[ukvStore arrayForKey:kVLCStoredServerList]];
@@ -137,8 +148,16 @@
 - (void)viewWillDisappear:(BOOL)animated
 {
     [super viewWillDisappear:animated];
-    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
-    [defaults setObject:_serverList forKey:kVLCStoredServerList];
+    NSUbiquitousKeyValueStore *ukvStore = [NSUbiquitousKeyValueStore defaultStore];
+    [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

+ 0 - 1
Sources/VLCOpenNetworkStreamViewController.m

@@ -57,7 +57,6 @@
     [super viewDidLoad];
 
     NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
-
     [notificationCenter addObserver:self
                            selector:@selector(ubiquitousKeyValueStoreDidChange:)
                                name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification