Firebase存储无法在iMessage扩展上运行

时间:2023-01-16 16:15:45

I am trying to integrate Firebase into an iMessage extension.

我正在尝试将Firebase集成到iMessage扩展中。

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.

作为测试,我正在设置Firebase并尝试在viewDidAppear方法中将本地文件保存到Firebase存储。 Firebase实时数据库在下面的代码中工作正常,只有存储部分没有。

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

完全相同的代码在普通应用程序中完成(即不是iMessage扩展)。

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 个解决方案

#1


2  

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

我怀疑iMessage扩展可能会限制访问文件系统(因为它们生活在与普通应用程序不同的沙箱中),因此获取文件将无法正常工作。在这种情况下putData工作,但putFile没有。解决方案:始终在内存中上传和下载(putData和dataWithMaxSize :) vs文件系统(putFile和writeFile)。

#1


2  

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

我怀疑iMessage扩展可能会限制访问文件系统(因为它们生活在与普通应用程序不同的沙箱中),因此获取文件将无法正常工作。在这种情况下putData工作,但putFile没有。解决方案:始终在内存中上传和下载(putData和dataWithMaxSize :) vs文件系统(putFile和writeFile)。