Bladeren bron

always transfer library on changes if a watch is paired
cancel old outstanding library transfers before starting the next one

Tobias Conradi 9 jaren geleden
bovenliggende
commit
4ee55279dc
1 gewijzigde bestanden met toevoegingen van 9 en 1 verwijderingen
  1. 9 1
      Sources/VLCWatchCommunication.m

+ 9 - 1
Sources/VLCWatchCommunication.m

@@ -176,7 +176,7 @@ static VLCWatchCommunication *_singeltonInstance = nil;
 }
 
 - (void)copyCoreDataToWatch {
-    if (![[WCSession defaultSession] isReachable]) return;
+    if (![[WCSession defaultSession] isPaired]) return;
 
     MLMediaLibrary *library = [MLMediaLibrary sharedMediaLibrary];
     NSPersistentStoreCoordinator *libraryPSC = [library persistentStoreCoordinator];
@@ -192,6 +192,14 @@ static VLCWatchCommunication *_singeltonInstance = nil;
         NSLog(@"%s failed to copy persistent store to tmp location for copy to watch with error %@",__PRETTY_FUNCTION__,error);
     }
 
+    // cancel old transfers
+    NSArray<WCSessionFileTransfer *> *outstandingtransfers = [[WCSession defaultSession] outstandingFileTransfers];
+    [outstandingtransfers enumerateObjectsUsingBlock:^(WCSessionFileTransfer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        if ([obj.file.metadata[@"filetype"] isEqualToString:@"coredata"]) {
+            [obj cancel];
+        }
+    }];
+
     NSDictionary *metadata = @{@"filetype":@"coredata"};
     [[WCSession defaultSession] transferFile:tmpURL metadata:metadata];
 }