Initial connection to Firebase seems fatally slow - ios

I've been developing an app that relies on its backend data being available almost immediately after opening. The app's home view is a table view controller that populates each of its cells with titles and then full cell background images. The titles come back quick enough as they are just strings but the images (of which im currently only loading 1-2 of them) on average take nearly 10-15 seconds. Also, when a user clicks one of these cells, this opens a collection view that has to load many more photos. I have been testing this with between 4 and 10 photos so far and it takes between 30 seconds and some times even minutes to pull these down. After these initial loads, it seems to be rather immediate when updates happen..even when several photos get added at once. This could be just the way Firebase stores to to a local copy of the Firebase on the device? Anyway, I was hoping someone could provide some insight as to why Firebase is loading this data so slowly. Is Firebase not capable of powering a photo heavy app? Or is the more likely user error of sorts holding me back?
Thanks in advance!

Related

ios - swift - reload data periodically

swift is outside of my core competency, so I apologize if this is very basic.
I have a page that shows data from a database that is continually updating, I'd like to have this page auto reload the data every few minutes so it is always showing recent data.
1- Reload every few minutes if app is left open.
2- Reload when app is brought back in to focus if it has been pushed to the background.
How should I implement such a function for ios/swift?
Best,

Application starts from Home Screen if app remains in the background for more than 30 seconds instead of showing the screen when it went to background

My iOS application is kind of messaging app, so user can send audio, video, images, etc. When user typing the message and app went background for more than 30 seconds then app launches from Home screen and all that messages, everything will be lost. Before 30 seconds app launches at the exact point where it went background. So how to do that same after 30 seconds also, at least I should maintain this state for 30 minutes.
Is using background process and schedule task will be a good method here in iOS 13+?
I particularly don't want to do anything on the background but when app comes from background to foreground within 30 minutes I want to maintain that state.
Messages Disappearing
Well, first of all, why are all the messages lost? if your trying to make a snapchat like experience where the messages disappear after you see them then that's fine but otherwise it might be worth adding a local storage for these messages using CoreData.
Cause
The main issue, after a little while iOS will but an app to sleep so to say, in this scenario it will remove all temporary data within your app, this means when you re-open it it will start from the beginning, it does this to save memory.
Solution
There are a few ways to solve this, you could use State Restoration
For a beginner though this could be quite tricky as the documentation on it is quite sparse.
Another option would be to save the last screen in UserDefaults and then when the app re-launches you can use the value to push the last screen the user was on. For both these solutions though you will need a way to persist the messages and re-fetch them (a database) CoreData would probs be your best bet
I do personally think State Restoration is the best option especially since it sounds like that's exactly what you want to do:
but when app comes from background to foreground within 30 minutes I want to maintain that state.

Launch screen for iOS

I have read a few posts on this topic about making the launch screen last longer, but I want to make it shorter.
Currently my launch screen takes 4 seconds before loading the login screen, and the app is not even close to being finished yet. Does that mean the launch screen could take longer to load once the app is finished?
Is there any way to make the launch screen appear for 2 seconds?
Xcode, Swift. backend in PHP.
The launch screen loading time depends on how "long" it takes your initial view controller to be prepared.
So, if you want it to "load faster" make your initial view controller more lightweight, do this by:
Reducing the number of interface elements being shown
Do not perform that many operations inside the "view did load" method.
Other than this, theres really not much you can do to control the time.
There isn't really a straightforward way of making the launch screen last shorter, because it depends on how long it takes for the necessities of your app to load.
Remember, the shorter the launch screen, the better, so the users of your app won't think that your app is taking a lot of time to boot up.

Slow launch time - how to navigate Time Profiler

I am developing my first iOS app and I am almost ready to submit to app store. However, I am having problems with launch time. It is taking ~3 seconds to launch. The app has a ContainerView with three UIViewControllers as Child View Controllers. The middle UIViewController is a camera and the left and right UIViewControllers are mostly made up of UITableViews that make basic network queries (not on main thread) to populate them. Basically, I am trying to figure out why my app takes 3 seconds whereas apps like SnapChat and Instagram take <1 second.
I tried seeing what was taking so long using Time Profiler in Instruments. There were a couple easy fixes but now I am stuck. It says 357ms are from main but when I double click on it, it just takes me to AppDelegate and shows me that AppDelegate is accounting for 100% (of the 357ms? - correct me if this is wrong). But this isn't helpful because I know that main() is to launch the app (?) but it isn't telling me anymore. Whereas when I click on other methods listed it breaks it down for me (i.e. what each part of the code is accounting for). This is my first time using Time Profiler and any help would be greatly appreciated.

Where do I cache media for a UITableView? What design pattern should I use?

I'm a new iOS developer pretty far in to my first app.
I have a UITableView that displays a lot of data, with small videos in the Section Headers. Right now in my builds I am embedding the videos in the app, but I'd like them to actually be fetched from a server since it takes too much space.
However, I'm not sure what kind of design pattern to use here. The section headers aren't allocated until they come on screen obviously. If I download the data in the background, and the user scrolls down to the section too early and doesn't get a video, and then the video finishes downloading in the background...how do I tell the TableView to now show the video?
Also, if I don't want to have to redownload approximately 3-4 MB of video every time the user loads up the tableview, what's the best way to actually save the videos somewhere (and delete them on application quit)? So, when the user loads the UITableView, it'll download those videos, cache them, and remove them once the user is no longer needs them?
My first instinct is to have a background thread saving the videos to a special location in the user's documents that is purged on application quit, and run [self.tableview reloadData] every single time one of the videos (each about 200kb) finishes downloading, but I don't know if doing ~20 tableview reloads will impact performance or the user's view (and does reloadData release and reload the section header that is on screen?).
Really appreciate any advice as to how to do this correctly.

Resources