Firebase存储无法在iMessage扩展上使用 [英] Firebase Storage not working on iMessage extension

查看:195
本文介绍了Firebase存储无法在iMessage扩展上使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将Firebase整合到iMessage扩展中。

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



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

我得到以下错误信息:

 错误域= FIRStorageErrorDomain代码= -13000 
发生未知错误,请检查服务器响应。
UserInfo = {ResponseErrorDomain = NSURLErrorDomain,object = test.jpg,
bucket = myapp.appspot.com,ResponseErrorCode = -995,$ b $`NSLocalizedDescription =发生未知错误,请检查服务器响应。

我正在做以下工作:

<$ p $ b $ super.viewDidAppear(动画)
FIRApp.configure()

FIRAuth.auth($ b $)$ func viewDidAppear(_ animated:Bool){
> )?signInAnonymously {(用户,错误)
guard让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)//产生错误
if错误!=无{
print(error.debugDescription)
}
}
FIRDatabase.database()。reference()。updateChildValues([someKey:someValue] )//正常工作



$ b $ div class =h2_lin>解决方案

我怀疑iMessage扩展可能会限制访问文件系统(因为他们生活在一个不同于规范的沙盒中应用程序),从而得到的文件将无法正常工作。在这种情况下, putData 可以工作,但是 putFile 不会。解决方案:在文件系统( putData 和 dataWithMaxSize: > putFile 和 writeFile )。


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

    }
  }

解决方案

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

这篇关于Firebase存储无法在iMessage扩展上使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆