Page loading with Firebase - ios

I use firebase in my ios app. For example, my database stores some data sets, which has being created by user. When user is authenticated, application starts downloading. But it is okay, when user has not bigger count of sets, because in this case, it is easy to download all data sets. On the other hand, if user has many-many data sets - it is terrible, because my app will download ALL this data immediately. How to use "page loading" with Firebase? For example - if user scroll to bottom, application starts downloading new piece of data from firebase database.

Related

When using NSPersistentCloudKitContainer: what to do if the user logs out of iCloud?

From several Apple WWDC talks on CloudKit, when using CloudKit to sync private user data across devices, when the user logs out of iCloud, the App is supposed to empty the on-device cache / local replica (I use Core Data for on-device permanence). Then when this user (or any user really) logs back into his respective iCloud account on that same device, the device is then supposed to sync back down the data from the corresponding iCloud account. Makes sense!
I was wondering how I can achieve this when I use NSPersistentCloudKitContainer (instead of writing all that CloudKit code myself). I looked at the sample code related to Apple WWDC 2019 session 202 ("Using Core Data with CloudKit"), and this code does not what I want (the sample just does not focus on the iCloud account part, that is why they do not bother to empty the cache, I think): Indeed the NSPersistentCloudKitContainer stops synching if I log out the user, but it picks up again synching when I log back in. That is actually more like the desired (and indeed also actual, which is good) behaviour by the sample App when my web connection goes offline for a while.
But if the user logs out of iCloud (I use CloudKit framework to be informed about user account logout and login status), what I would need to do is somehow:
"disconnect" the sqlite store from the NSPersistentCloudKitContainer, then
empty (or even delete) the database, and then,
when the old (or another) user logs in, initialise a new NSPersistentCloudKitContainer (that will recreate an empty database as if the App would be used for the first time ever), so communication with the respective Cloud database can proceed.
I can not just empty the database WHILE being "connected" to the NSPersistentCloudKitContainer, as it records all the deletes and as soon as the (same) user logs in again, these deletes are synched to the Cloud, which I of course do NOT want.
Is this how one does it, aka essentially follow these three steps?
And if yes, how do I do step 2? Since I must use some kind of NSPersistentContainer to talk to the database, Apple warns not to directly do file system operations but only via Core Data. So do I need to init a "standard" NSPersistentContainer (without a communication pipe to the Cloud), and then destroy the database (e.g. using e.g. the coordinator instance method destroyPersistentStore())?
Or is there another approach for achieving the same thing?
Thank you very much for any help!!

What is the best way to add data on a daily basis to a tableview in my published iOS app?

I have a tableview in an app which is holding much more data in an array than it should be.
I would like to publish the app with the current data and continue to upload data into that tableview daily in the near future.
Is it possible to have the data added to the tableview daily in the same way that I've been adding it into the viewController through a swift file before it was published?
You can use the firebase database to store data and show them on daily basis to a tableview. Whenever firebase database will be updated, iOS application will get database change notification. You can update your tableview based on this notification with the new data. Firebase even has offline capabilities which means it can persist data locally so that data can be accessed when there is no internet connection.
https://firebase.google.com/docs/database
https://firebase.google.com/docs/database/ios/start
https://firebase.google.com/docs/database/ios/offline-capabilities

What is considered too heavy for UserDefaults?

I'm building a simple iOS app that will be the first I'll have put on Apple's App Store. At one point, the app accesses the user's contact list and lets them select any number of contacts they want to save as favorites.
For ease of building version one, I am currently using UserDefaults to save these favorites. While it has worked well in my limited testing, I know that Core Data and CloudKit are stable options for larger solutions.
For an app like mine, where I'm only using UserDefaults to save a select number of contacts as favorites, is UserDefaults an adequate solution? Or should I transition to something more robust like Core Data or CloudKit? There is no limit on the number of contacts a user could select as a favorite, so there is the edge-case possibility of a user selecting all of their contacts one by one and attempting to save them all as favorites.
If the user gets a new phone and loses all existing data due to UserDefaults being local on the device, it would not take long to get this app back to where they previously had it.
You can use CoreData to store favorite contact locally for large data as per your concern. Now when user switch device or delete app then all data will removed. So for that you can sync with cloudKit or other option is backend server. When user add any contact as favourite same time that contact will add to Core data as well as in backend server. You can sync this backend server data when user login first time in the app, then you no need to sync again. other all thing are as per requirement.

Pushing data to all devices when database changes with Realm Swift

I know that Realm offers two way syncing and can trigger server-side events when data changes.
I am making a sort of messaging app, my question is how would I implement it so that when someone writes a message (which will update the DB), how does this message immediately display on other devices?
All you have to do is to open the same Realm on all devices, then they will all see the changes instantly as they happen (as long as they are connected of course :-)).
Check out the tutorial, it shows the data being realtime synced between both an iOS app, a Mac app and the Realm Browser: https://realm.io/docs/tutorials/realmtasks/
I'm one of the developers working on Realm Tasks, incorporating the latest features of the Realm Mobile Platform into it. :)
Making a chat app has become significantly easier with the release of client Realm sharing in Realm 2.3.
To make a chat app, the logic flow would be something like this:
A user starts a new chat room. This would be represented in RMP as a single, private Realm file belonging to that user.
The user can then invite other users access to that chat room via the sharing mechanism.
Every user can then contribute messages. Each message would be a separate Realm Object written to the shared Realm.
Each time a new chat message object is written to the Realm, it would be synchronized with every other user in the room.
Please let me know if you need any additional clarification.

How to update an ios App with current information daily

I'm trying to design an app for my club at school. What I want to happen is when there is new information about meetings or events I want to be able to add this new content to the app and then have it visible by other app users.
So my question is how would I approach this idea?
Conceptually, you're going to need to have a centralized server which contains the data, an API to connect an application to this data, and finally the end user application.
On the server end, you could have a simple database which will house the event and meeting information.
On the API end, you could have a simple script which fetches the latest entries in the database and displays the data in a standard format such as JSON or XML.
On the app end, every time the user opens the application, fetch the latest data from your API and parse it into an array. Then, just populate a table or collection with the data in that array. You could also add a pull to refresh control to fetch the latest information at any time so the user doesn't have to launch the app again.

Resources