且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有更多照片的iOS Swift应用:性能和存储建议

更新时间:2023-01-23 19:30:46

您可以通过以下方式进行操作:

You can do it next way:

1)将文件上传到Firebase存储并获取下载网址:

1) Upload file to firebase storage and get download url for it:

static func upload(_ image: UIImage,
                  completion: @escaping (_ hasFinished: Bool, _ url: String) -> Void) {
let data: Data = UIImageJPEGRepresentation(image, 1.0)!

// ref should be like this
let ref = FIRStorage.storage().reference(withPath: "media/" + userId + "/" + unicIdGeneratedLikeYouWant)
ref.put(data, metadata: nil,
                   completion: { (meta , error) in
                    if error == nil {
                       // return url
                       completion(true, (meta?.downloadURL()?.absoluteString)!)
                    } else {
                       completion(false, "")
                    }
  })

然后使用 FIRDatabase 将上传的照片的url保存到用户节点。看起来像这样:

Then save url of the uploaded photo to user node with FIRDatabase. It will look like:

但是例如是帖子ID,而不是 mediaRef10 mediaRef700

But it will be posts ids for example instead of mediaRef10 and mediaRef700

因此,您将在用户节点中具有照片的链接,并且可以轻松获得具有良好性能的照片。

So, you will have in user node links to photos and you can easy get them with good perfomance.