Here is the code that handles the FTP upload:
let finalRemoteName = self.fileName + ".jpg"
let dispatch = DispatchQueue(label: "Uploader", qos : .background)
let ftp = FTPAccess.init(baseUrl: FTP_URL, userName: FTP_USERNAME, password: FTP_PW, remotePath: "")
dispatch.async {
guard let ftpStream = ftp.ftpWriteStream(forFileName:
finalRemoteName)
else {
self.errorMessage = "Failed to create FTPStream"
self.result = .Error
self.resultMessage = "Failed"
return
}
if CFWriteStreamOpen(ftpStream) == false {
self.errorMessage = "Could not open FTPStream"
self.resultMessage = "Failed"
self.result = .Error
}
let fileSize = self.data.count
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: fileSize)
self.data.copyBytes(to: buffer, count: fileSize)
defer {
CFWriteStreamClose(ftpStream)
buffer.deallocate(capacity: fileSize)}
var offset: Int = 0
var dataToSendSize: Int = fileSize
repeat {
DispatchQueue.main.async {
self.progress = 1.0 -
Float(dataToSendSize) / Float(fileSize)
}
let bytesWritten = CFWriteStreamWrite(ftpStream,
&buffer[offset], dataToSendSize)
if (bytesWritten > 0) {
offset += bytesWritten.littleEndian
dataToSendSize -= bytesWritten
continue
}
else if (bytesWritten < 0) {
self.errorMessage = "FTP Upload Error"
self.resultMessage = "Failed"
self.result = .Error
return
}
else if (bytesWritten == 0) {
print("Finished Upload")
DispatchQueue.main.sync {
self.resultMessage = "Success"
self.result = .Success
}
return
}
}. while (true) }.
return self.result
}
}
}`
Again, this works perfectly on the simulator, all versions, and for older iPhone models. On newer iPhone models the upload simply isn't working and I'm not sure why.
Here are my questions?
-
How would you go about capturing the error message IF there is an error message being captured because it's not causing a crash that would show up in TestFlight?
-
Could this possibly be a case of the info file being incorrect for an app that communicates with an external FTP server? If so, why does it work for older phones but not newer ones and what is the solution?
-
Another problem I'm facing is that the upload speed is terribly slow. It's not like this on the Android version of the app so I know it's not an issue with the server itself. Do you see anything in here that would possibly limit the chunk size of the uploaded image possibly? Is there another reason I'm missing?