Переглянути джерело

dropbox controller: added support to share credentials

Felix Paul Kühne 9 роки тому
батько
коміт
a28cf2ce23

+ 1 - 0
Sources/VLCConstants.h

@@ -86,6 +86,7 @@
 #endif
 
 #define kVLCStoredServerList @"kVLCStoredServerList"
+#define kVLCStoreDropboxCredentials @"kVLCStoreDropboxCredentials"
 
 #define kVLCUserActivityPlaying @"org.videolan.vlc-ios.playing"
 #define kVLCUserActivityLibrarySelection @"org.videolan.vlc-ios.libraryselection"

+ 3 - 0
Sources/VLCDropboxController.h

@@ -23,6 +23,9 @@
 
 + (instancetype)sharedInstance;
 
+- (void)shareCredentials;
+- (BOOL)restoreFromSharedCredentials;
+
 - (void)downloadFileToDocumentFolder:(DBMetadata *)file;
 - (void)streamFile:(DBMetadata *)file;
 

+ 28 - 1
Sources/VLCDropboxController.m

@@ -20,6 +20,7 @@
 #import "VLCActivityManager.h"
 #import "VLCMediaFileDiscoverer.h"
 #endif
+#import "DBKeychain.h"
 
 @interface VLCDropboxController ()
 {
@@ -50,11 +51,36 @@
 
     dispatch_once(&pred, ^{
         sharedInstance = [VLCDropboxController new];
+        [sharedInstance shareCredentials];
     });
 
     return sharedInstance;
 }
 
+- (void)shareCredentials
+{
+    /* share our credentials */
+    NSDictionary *credentials = [DBKeychain credentials];
+    if (credentials == nil)
+        return;
+
+    NSUbiquitousKeyValueStore *ubiquitousStore = [NSUbiquitousKeyValueStore defaultStore];
+    [ubiquitousStore setDictionary:credentials forKey:kVLCStoreDropboxCredentials];
+    [ubiquitousStore synchronize];
+}
+
+- (BOOL)restoreFromSharedCredentials
+{
+    NSUbiquitousKeyValueStore *ubiquitousStore = [NSUbiquitousKeyValueStore defaultStore];
+    [ubiquitousStore synchronize];
+    NSDictionary *credentials = [ubiquitousStore dictionaryForKey:kVLCStoreDropboxCredentials];
+    if (!credentials)
+        return NO;
+
+    [DBKeychain setCredentials:credentials];
+    return YES;
+}
+
 - (void)startSession
 {
     [[DBSession sharedSession] isLinked];
@@ -139,7 +165,8 @@
     return NO;
 }
 
-- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
+- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata
+{
     NSMutableArray *listOfGoodFilesAndFolders = [[NSMutableArray alloc] init];
 
     if (metadata.isDirectory) {