Просмотр исходного кода

box controller: add token sharing

Felix Paul Kühne 9 лет назад
Родитель
Сommit
060db6e8d4
3 измененных файлов с 12 добавлено и 0 удалено
  1. 8 0
      Sources/VLCBoxController.m
  2. 3 0
      Sources/VLCBoxTableViewController.m
  3. 1 0
      Sources/VLCConstants.h

+ 8 - 0
Sources/VLCBoxController.m

@@ -58,6 +58,11 @@
     [BoxSDK sharedSDK].OAuth2Session.clientID = kVLCBoxClientID;
     [BoxSDK sharedSDK].OAuth2Session.clientSecret = kVLCBoxClientSecret;
     NSString *token = [SSKeychain passwordForService:kVLCBoxService account:kVLCBoxAccount];
+    if (!token) {
+        NSUbiquitousKeyValueStore *ubiquitousStore = [NSUbiquitousKeyValueStore defaultStore];
+        [ubiquitousStore synchronize];
+        token = [ubiquitousStore stringForKey:kVLCStoreBoxCredentials];
+    }
     if (token != nil) {
         [BoxSDK sharedSDK].OAuth2Session.refreshToken = token;
     }
@@ -74,6 +79,9 @@
 {
     [SSKeychain deletePasswordForService:kVLCBoxService account:kVLCBoxAccount];
     [[BoxSDK sharedSDK].OAuth2Session logout];
+    NSUbiquitousKeyValueStore *ubiquitousStore = [NSUbiquitousKeyValueStore defaultStore];
+    [ubiquitousStore setString:nil forKey:kVLCStoreBoxCredentials];
+    [ubiquitousStore synchronize];
     [self stopSession];
     if ([self.delegate respondsToSelector:@selector(mediaListUpdated)])
         [self.delegate mediaListUpdated];

+ 3 - 0
Sources/VLCBoxTableViewController.m

@@ -188,6 +188,9 @@
 {
     NSString *token = [BoxSDK sharedSDK].OAuth2Session.refreshToken;
     [SSKeychain setPassword:token forService:kVLCBoxService account:kVLCBoxAccount];
+    NSUbiquitousKeyValueStore *ubiquitousStore = [NSUbiquitousKeyValueStore defaultStore];
+    [ubiquitousStore setString:token forKey:kVLCStoreBoxCredentials];
+    [ubiquitousStore synchronize];
     self.authorizationInProgress = YES;
     [self updateViewAfterSessionChange];
     self.authorizationInProgress = NO;

+ 1 - 0
Sources/VLCConstants.h

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