Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Firebase Storage Error 'Upload attempting to execute on non main queue

I know that firebase callbacks are running on the Main thread. However, I am dispatching my code inside putData completion block on the main thread and I still get error:

2018-12-17 16:40:59.351252+0000 SalsaWorld[3560:854920] * Assertion failure in -[FIRStorageUploadTask enqueue], /Users/bogdanbarbulescu/Desktop/SalsaWorld/Pods/FirebaseStorage/Firebase/Storage/FIRStorageUploadTask.m:73 2018-12-17 16:40:59.351852+0000 SalsaWorld[3560:854920] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Upload attempting to execute on non main queue! Please only execute this method on the main queue.' *** First throw call stack: (0x1ddefb3d 0x1d077067 0x1ddefa19 0x1e6e552d 0x1db4bb 0x1d6321 0x810a4 0x9ebc8 0x9dbe4 0x9d35c 0x9aa1c 0x246ed049 0x1413467 0x141f66f 0x1416a39 0x141fb31 0x142176b 0x1421471 0x1d67287d 0x1d67245c) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

   func uploadVideo(uid: String, storageRef: StorageReference, completion: @escaping (Error?, String?) -> Void) -> StorageUploadTask! {

    var task: StorageUploadTask!
    let metadata = StorageMetadata()
    let myAudioData = audioData as Data
    metadata.contentType = "audio/mp4a"
    metadata.contentDisposition = ""

    task = storageRef.putData(myAudioData, metadata: metadata) { (metadata, error) in

        DispatchQueue.main.async {
            guard error == nil else {
                completion(error, nil)
                return
            }

            storageRef.downloadURL(completion: { (url, error) in

                guard let downloadUrl = url else {
                    completion(error, nil)
                    return
                }
                print("the downloadUrl is \(downloadUrl)")

                let audioAbsoluteString = downloadUrl.absoluteString
                print("audioAbsoluteString is \(audioAbsoluteString)")
                completion(error, audioAbsoluteString)
            })
        }//dispatch 

    }

    return task
}

Comments