iOS Swift App with more photos: Performance and Storage suggestions

廉价感情. 提交于 2019-12-13 12:51:27

问题


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.

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

Thank you


回答1:


You can do it next way:

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, "")
                    }
  })

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

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.



来源:https://stackoverflow.com/questions/43926284/ios-swift-app-with-more-photos-performance-and-storage-suggestions

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