Nilsymbol Nilsymbol - 10 months ago 116
Swift Question

Firebase storage not working on iMessage extension

I am trying to integrate Firebase into an iMessage extension.

As a test i am setting up Firebase and trying to save a local file to firebase storage in the viewDidAppear method. The Firebase real time database works fine in the code below, only the storage part does not work.

The exact same code works when done in a normal app (i.e. not a iMessage extension).

I get the following error message:

Error Domain=FIRStorageErrorDomain Code=-13000
"An unknown error occurred, please check the server response."
UserInfo={ResponseErrorDomain=NSURLErrorDomain, object=test.jpg,, ResponseErrorCode=-995,
`NSLocalizedDescription=An unknown error occurred, please check the server response.

I am doing the following:

override func viewDidAppear(_ animated: Bool) {

FIRAuth.auth()?.signInAnonymously { (user, error) in
guard let fileURL = Bundle.main.url(forResource: "test", withExtension:"jpg") else { return }

let storageRef ="test.jpg")
storageRef.putFile(fileURL, metadata: nil) { (metaData, error) in //produces error
if error != nil {
FIRDatabase.database().reference().updateChildValues(["someKey" : "someValue"]) // works fine


Answer Source

I have a suspicion that iMessage extensions may get limited access to the file system (since they live in a different sandbox than the normal app), and thus getting the file wouldn't work. In this case putData works, but putFile doesn't. Solution: always upload and download in memory (putData and dataWithMaxSize:) vs the file system (putFile and writeFile).