Firebase Storage not working on iMessage extension

痴心易碎 提交于 2019-12-23 01:37:30

问题


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.

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,
bucket=myapp.appspot.com, ResponseErrorCode=-995, 
`NSLocalizedDescription=An unknown error occurred, please check the server response.

I am doing the following:

  override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    FIRApp.configure()

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

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

    }
  }

回答1:


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).



来源:https://stackoverflow.com/questions/39689929/firebase-storage-not-working-on-imessage-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!