-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebDavFileProvider example #32
Comments
Please check latest version (0.15.0), I think this bug would be fixed already |
I tried to test the code with version (0.15.0) but I have not noticed any changes. Delegate does not work and is not communicated anything when the file was created. |
I can't understand how creating a folder can have a progress. It will either fail or succeed. |
@CPiersigilli please check 0.15.2 |
I check 0.15.2.
I modified the code to create and read the "/Text/newFile2.txt" file, but still does not work as I would like. Can you help me? Sorry for my English.
|
Are you sure you are using 0.15.2? |
Yes. Because I'm using this code in a new mac. |
I'm sure to use the 0.15.2 version, but how can I see it? |
latest cocoa pods version is 0.15.1 if you are using pods |
No. I use |
In the sample code above, I have tried to insert your:
Where should I put the above code does not have errors? |
Please initialize And questions:
You should do
That's a bug in Apple's framework. Don't pay attention to that.
That works fine for me! That's probably because you are initializing provider inside functions which will be released before completion handler runs! If you initialize it inside And thank you for noting that I forgot to make |
I've fixed it for you test it: import Cocoa
import FileProvider
class ViewController: NSViewController, FileProviderDelegate {
@IBOutlet weak var writeText: NSTextField!
@IBOutlet weak var textSavedFromFile: NSTextField!
@IBOutlet weak var folderList: NSTextField!
var webdavFile: WebDAVFileProvider?
var operation: OperationHandle?
@IBAction func saveText(_ sender: NSButton) {
let path = "newFile2.txt"
let nameFolder = "Text"
let atFolder = "/"
let atFile = atFolder + nameFolder + atFolder + path
if writeText.stringValue != "" {
let data = writeText.stringValue.data(using: .utf8)
operation = webdavFile?.create(folder: nameFolder, at: atFolder, completionHandler: { error in
if error == nil {
print("The folder was created successfully.")
}
else
{
print("The folder was not created for the following error: \(error)")
}
operation = webdavFile?.writeContents(path: atFile, contents: data, atomically: false, overwrite: true, completionHandler: { error in
if error == nil {
print("The file was created with: \(self.operation).")
}
else
{
print("The file was not created for the following error: \(error)")
}
})
})
}
}
@IBAction func readText(_ sender: NSButton) {
let path = "/Text/newFile2.txt"
operation = webdavFile?.contents(path: path, completionHandler: {
contents, error in
if error == nil {
if let contents = contents {
print("The file contains: \(String(data: contents, encoding: .utf8))")
self.textSavedFromFile.stringValue = String(data: contents, encoding: .utf8)!
}
}
else
{
print("Error: \(error)")
}
})
}
@IBAction func folderList(_ sender: NSButton) {
let atFolder = "/"
webdavFile?.contentsOfDirectory(path: atFolder, completionHandler: {
contents, error in
if error == nil {
var localFolderList = "Name Size Creation Date Modification Date"+"\n"
for file in contents {
localFolderList += "\(file.name) \(file.size) \(file.creationDate!) \(file.modifiedDate!) \n"
}
print(localFolderList)
self.folderList.stringValue = localFolderList
}
else
{
print("Error: \(error)")
}
})
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let user = "xxx@xxxxx.it"
let password = "xxxxx"
credential = URLCredential(user: user, password: password, persistence: .forSession)
myUrlWebdav = URL(string: "https://webdav.pcloud.com")
webdavFile = WebDAVFileProvider(baseURL: myUrlWebdav!, credential: credential)
webdavFile?.delegate = self as? FileProviderDelegate
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
func fileproviderSucceed(_ fileProvider: FileProviderOperations, operation: FileOperationType) {
switch operation {
case .fetch(path: let pathFile):
print("fetch file from: \(pathFile).")
case .modify(path: let pathFile):
print("modify file: \(pathFile).")
case .copy(source: let source, destination: let dest):
print("\(source) copied to \(dest).")
case .remove(path: let path):
print("\(path) has been deleted.")
case .create(path: let pathFile):
print("created file: \(pathFile).")
case .move(source: let source, destination: let dest):
print("\(source) moved to \(dest).")
default:
print("\(operation.actionDescription) from \(operation.source!) to \(operation.destination) succeed")
}
}
func fileproviderFailed(_ fileProvider: FileProviderOperations, operation: FileOperationType) {
switch operation {
case .create(path: let pathFile):
print("create file: \(pathFile) failed.")
case .modify(path: let pathFile):
print("modify file: \(pathFile) failed.")
case .copy(source: let source, destination: let dest):
print("copy of \(source) to \(dest) failed.")
case .remove:
print("file can't be deleted.")
default:
print("\(operation.actionDescription) from \(operation.source!) to \(operation.destination) failed")
}
}
func fileproviderProgress(_ fileProvider: FileProviderOperations, operation: FileOperationType, progress: Float) {
switch operation {
case .copy(source: let source, destination: let dest):
print("Copy\(source) to \(dest): \(progress * 100) completed.")
case .create(path: let pathFile):
print("Create file or folder to \(pathFile): \(progress * 100) completed.")
case .fetch(path: let pathFile):
print("fecth file or folder to \(pathFile): \(progress * 100) completed.")
default:
break
}
}
} |
By the way to get |
With the changes, for each function, now the situation is:
|
Did you copy this line? class ViewController: NSViewController, FileProviderDelegate { |
Well, that's justifies why delegate doesn't work. I can't help you much if you can't conform your class to a protocol. |
With reference to the above code, how can I make the class |
Xcode should tell you which methods are unimplemented, but implementing all 3 methods, without omitting any of these, |
Excuse me, I had commented |
Can I have error returned by |
Unfortunately no errors. The procedure skips to the end of the completion handler. |
This is the code for
|
ERRORE SCONOSCIUTO in english: UNKNOWN ERROR. Excuse me. |
Does the completion handler is called or not? |
Probably not, because the code jump from |
That jump is because the completion handler will run asynchronously. That's normal. You should put.a breakpoint inside closure, like line 4 in this sample |
|
I have tried to insert breakpoints anywhere without getting anything (line 5, 6, 7, 8 ....). |
I can't understand the purpose of that. |
This code is working for me. Can't find what's going wrong here. But I will do further testing later |
To test |
To perform other tests, I have rewritten the app for ios: but only |
Not a problem only a hint. Just remove |
Ok. Hint removed. And for |
It works for me. I don't know what to do. It's open source and you can alter the codes which don't work. |
@CPiersigilli I've tested |
@amosavian I'm very happy. Thank you. I will wait for your news. |
Fixed in ff5e139 (version 0.15.3) |
I test my code with version (0.15.3) and now work fine. Thank you. |
sorry for inconvenience |
Don't worry. Thanks for the library that you have written. |
This is my example code for os x:
My problems are:
Can anyone change the code so that it works?
Thank you
Cesare Piersigilli
The text was updated successfully, but these errors were encountered: