ios - swift - reload data periodically - ios

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,

Related

Does firebase functions keep running after dissiming a view-controller

I am a newbie in iOS development/firebase.
I have two view controller,
the first one does nothing expect performing a segue to the second view-controller
The second the view controller I have two buttons,the firstone is (back) which dismiss a view controller and the second button(up) have the following code
Database.database().child(“posts”).setValue(1)
1- If I have an extremely bad internet connection, and I pressed on up button then immediately pressed on back,
Does the code for uploading data for firebase stop on continue?
2- After pressing up, I immediately go to background and dismiss the app, will it continue setting the data?
All database operations are handled on another thread that's not related to any UI elements in your app. As long as your app is running, database operations will continue until complete.
If the app is no longer running, database operations will stop. If database persistence is not enabled, all of that pending work will never complete. If database persistence is enabled, then the SDK will try again to synchronize the writes that didn't complete previously.

Initial connection to Firebase seems fatally slow

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!

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.

App update data from web periodically

I'm building an iPhone app where most of the content is dynamically loaded from my web server. The content is updated once per day. Here's the issue I ran into when testing my app on my device. I noticed that I would just close the app, and the next day I didn't see the new content. I had to go close the app fully (via multitasking) and then go back into it to update the content.
I could use this in the app delegate:
- (void)applicationWillEnterForeground:(UIApplication *)application
but, I load all the content in each View Controller... how should I go about re-loading my data?
Also...
If I update the array of objects that the data is pulled from in the UITableView, will the UITableView update automatically?
Thanks for any help!!
Note the documentation for that method also says, "The application also posts a UIApplicationWillEnterForegroundNotification notification shortly before calling this method to give interested objects a chance to respond to the transition."
Your view controller could be considered an interested object.
Table views can be told to reloadData.

Displaying live ticker data in iOS app

I am consuming data from a REST Web Service via RestKit and would like to display it in a tableview. Consuming the data works really good. Now I want to display the data in a table. The web service is requested every two seconds.
How would you implement the tableview? How to get to know changes? Is there some mechanism in iOS that helps to get the delta?
I think there is no mechanism that helps you out. But you can consume the data on another thread (in the background) and "append" the rows to the TableView, dont use reload than your tableview isn't useable.
Load up your tableview with data.
Start an process in the background wich calls your webservice every 2 seconds.
Create an observer and send an notification when the call is done.
And than append the rows (with animation for example) to the tableview.
I hope that helps you out a bit =]

Resources