Firebase Storage
はあなたがpause()
、cancel()
、およびresume()
は私が設定しますhere
を読むことができる機能を持っているにStorageUploadTask
として私は一時停止またはcaを置くだろうクラスプロパティDispatchWorkItem
を使用してDispatchAsync Timer
でncel:
// 1. make sure you `import Firebase` to have access to the `StorageUploadTask`
import Firebase
var timeoutTask: DispatchWorkItem?
var downloadTask: StorageUploadTask?
// using your code from your question
let storage = FIRStorage.storage()
let storageRef = storage.reference(forURL: "gs://...")
let fileRef = storageRef.child(myLink)
// 2. this cancels the downloadTask
timeoutTask = DispatchWorkItem{ [weak self] in
self?.downloadTask?.cancel()
}
// 3. this executes the code to run the timeoutTask in 5 secs from now. You can cancel this from executing by using timeoutTask?.cancel()
DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: timeoutTask!)
// 4. this initializes the downloadTask with the fileRef your sending the data to
downloadTask = fileRef.write(toFile: url) {
(url, error) in
self.timeoutTask?.cancel()
// assuming it makes it to this point within the 5 secs you would want to stop the timer from executing the timeoutTask
self.timeoutTask = nil // set to nil since it's not being used
}
残念ながらFirebaseがRealTimeDatabase
ため、この機能は利用できていません