本文介绍了带有更多照片的iOS Swift应用:性能和存储建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个iOS应用程序,用户可以在该应用程序中上传照片,有人可以建议最好和有效的方法来处理存储和性能问题。
考虑每个用户一个月内将上传约300张照片(最坏的情况)。
我的基本想法是在本地使用文档目录存储图像,然后将其与FireBase同步。

I am trying to develop an iOS application where users upload photos, can someone please suggest best and efficient ways to handle the storage and performance issues.Consider each user will be uploading around 300 photos in a month (worst case scenario). My basic idea was to use Document Directory locally to store images and then sync it with FireBase.

我是在iOS中开发应用程序的初学者,愿意知道启动我的应用的最佳实践。

I am a beginner in developing apps in iOS, willing to know the best practices to start my app.

谢谢

推荐答案

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

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.

这篇关于带有更多照片的iOS Swift应用:性能和存储建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 17:20