@@ -32,7 +32,6 @@ class NCService: NSObject {
3232 } ( )
3333
3434 let appDelegate = UIApplication . shared. delegate as! AppDelegate
35- var jsonCapabilities : JSON ?
3635
3736 // MARK: -
3837
@@ -62,19 +61,54 @@ class NCService: NSObject {
6261
6362 private func requestServerCapabilities( completion: @escaping ( ) -> Void ) {
6463
64+ let capabilitiesDirectEditingSupportsFileId : Array = [ " ocs " , " data " , " capabilities " , " files " , " directEditing " , " supportsFileId " ]
65+ let capabilitiesDirectEditing : Array = [ " ocs " , " data " , " capabilities " , " richdocuments " , " direct_editing " ]
66+ let capabilitiesNotesVersion : Array = [ " ocs " , " data " , " capabilities " , " notes " , " version " ]
67+ let capabilitiesNotesApiVersion : Array = [ " ocs " , " data " , " capabilities " , " notes " , " api_version " ]
68+
6569 NextcloudKit . shared. getCapabilities { account, data, error in
6670 if error == . success, let data = data {
67- self . jsonCapabilities = JSON ( data)
68- if let jsonCapabilities = NCService . shared. jsonCapabilities,
69- let version = jsonCapabilities [ NCElementsJSON . shared. capabilitiesNotesVersion] . string,
70- let apiVersion = jsonCapabilities [ NCElementsJSON . shared. capabilitiesNotesApiVersion] . array? . last? . string {
71- KeychainHelper . notesVersion = version
72- KeychainHelper . notesApiVersion = apiVersion
73- }
74- } else {
75- self . jsonCapabilities = nil
71+ data. printJson ( )
72+ let jsonCapabilities = JSON ( data)
73+ KeychainHelper . directEditing = jsonCapabilities [ capabilitiesDirectEditing] . boolValue
74+ KeychainHelper . directEditingSupportsFileId = jsonCapabilities [ capabilitiesDirectEditingSupportsFileId] . boolValue
75+ KeychainHelper . notesVersion = jsonCapabilities [ capabilitiesNotesVersion] . stringValue
76+ KeychainHelper . notesApiVersion = jsonCapabilities [ capabilitiesNotesApiVersion] . array? . last? . string ?? " "
7677 }
7778 completion ( )
7879 }
7980 }
8081}
82+
83+ extension Data {
84+
85+ func printJson( ) {
86+ do {
87+ let json = try JSONSerialization . jsonObject ( with: self , options: [ ] )
88+ let data = try JSONSerialization . data ( withJSONObject: json, options: . prettyPrinted)
89+ guard let jsonString = String ( data: data, encoding: . utf8) else {
90+ print ( " Inavlid data " )
91+ return
92+ }
93+ print ( jsonString)
94+ } catch {
95+ print ( " Error: \( error. localizedDescription) " )
96+ }
97+ }
98+
99+ func jsonToString( ) -> String {
100+ do {
101+ let json = try JSONSerialization . jsonObject ( with: self , options: [ ] )
102+ let data = try JSONSerialization . data ( withJSONObject: json, options: . prettyPrinted)
103+ guard let jsonString = String ( data: data, encoding: . utf8) else {
104+ print ( " Inavlid data " )
105+ return " "
106+ }
107+ return jsonString
108+ } catch {
109+ print ( " Error: \( error. localizedDescription) " )
110+ }
111+ return " "
112+ }
113+ }
114+
0 commit comments