Unfortunately, it is next to impossible to "share" things with iCloud Drive. Use Dropbox. Here is the code to save your file, you need to setup the DropboxClientsManager.authorizedClient variable first of course, checkout their dev pages. Corepath is the path for your file.
let client = DropboxClientsManager.authorizedClient!
client.files.upload(path: corePath, mode: .overwrite, autorename: false, input: textData).response { response, error in
if let metadata = response {
// Get file (or folder) metadata
}
if let error = error {
switch error {
case .routeError(let boxed, let requestId):
switch boxed.unboxed {
case .path(let failedPath):
//rint("Failed update 2 path: \(failedPath)")
NotificationCenter.default.post(name: Notification.Name("dbFileCreationError"), object: nil, userInfo: nil)
break
default:
////rint("Unknown \(error)")
break
}
case .internalServerError(let code, let message, let requestId):
////rint("InternalServerError[\(requestId)]: \(code): \(message)")
NotificationCenter.default.post(name: Notification.Name("dbInternalServerError"), object: nil, userInfo: nil)
break
case .badInputError(let message, let requestId):
////rint("BadInputError[\(requestId)]: \(message)")
NotificationCenter.default.post(name: Notification.Name("dbBadInputError"), object: nil, userInfo: nil)
break
case .authError(let authError, let requestId):
////rint("AuthError[\(requestId)]: \(authError)")
NotificationCenter.default.post(name: Notification.Name("dbAuthError"), object: nil, userInfo: nil)
break
case .rateLimitError(let rateLimitError, let requestId):
////rint("RateLimitError[\(requestId)]: \(rateLimitError)")
NotificationCenter.default.post(name: Notification.Name("dbRateLimitError"), object: nil, userInfo: nil)
break
case .httpError(let code, let message, let requestId):
////rint("HTTPError[\(requestId)]: \(code): \(message)")
NotificationCenter.default.post(name: Notification.Name("dbHTTPError"), object: nil, userInfo: nil)
break
default:
break
}
}
}
}