瀏覽代碼

dev NCService

Marino Faggiana 7 年之前
父節點
當前提交
7d2f902aae
共有 1 個文件被更改,包括 27 次插入3 次删除
  1. 27 3
      iOSClient/Networking/NCService.swift

+ 27 - 3
iOSClient/Networking/NCService.swift

@@ -135,14 +135,38 @@ class NCService: NSObject, OCNetworkingDelegate, CCLoginDelegate, CCLoginDelegat
             CCNetworking.shared().settingAccount()
             appDelegate.settingActiveAccount(tableAccount.account, activeUrl: tableAccount.url, activeUser: tableAccount.user, activeUserID: tableAccount.userID, activePassword: tableAccount.password)
             
+            // Call func thath required the userdID
+            appDelegate.activePhotos.readPhotoVideo()
+            appDelegate.activeFavorites.readListingFavorites()
+            
+            DispatchQueue.global(qos: .default).async {
+                
+                guard let imageData = try? Data(contentsOf: URL(string: "\(self.appDelegate.activeUrl)/index.php/avatar/\(self.appDelegate.activeUser)/128")!) else {
+                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "changeUserProfile"), object: nil)
+                    return
+                }
+                
+                guard let avatar = UIImage(data: imageData) else {
+                    try? FileManager.default.removeItem(atPath: "\(self.appDelegate.directoryUser)/avatar.png")
+                    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "changeUserProfile"), object: nil)
+                    return
+                }
+                
+                if let data = UIImagePNGRepresentation(avatar) {
+                    try? data.write(to: URL(string:"\(self.appDelegate.directoryUser)/avatar.png")!)
+                }
+                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "changeUserProfile"), object: nil)
+            }
+            
         } else {
             
+            let error = "Get user profile failure error \(errorCode) \(message!)"
+            print("[LOG] \(error)")
+            
+            NCManageDatabase.sharedInstance.addActivityClient("", fileID: "", action: k_activityDebugActionCapabilities, selector: "Get user profile Server", note: error, type: k_activityTypeFailure, verbose: true, activeUrl: appDelegate.activeUrl)
         }
-        
-        
     }
     
-    
     //MARK: -
     //MARK: Delegate : Login