Swift - Using URLSessionStreamTask to keep my app in sync with Firebase DB data - swift

I came across this link trying to figure out how to access the REST api of my firebase database and stream it to my app. I can get/send data manually, but for my app I can't use the firebase api (because it is an app clip), so I'm trying to do it with native tools and rest, but the issue I'm running into is getting the configuration right (per this info) and actually parsing the incoming info and updating my app. I'm so lost and could use some help just figuring out how to make the code in the sample work, especially since I'm using swift ui as well.
Any help is appreciated, thanks!

Apparently App Clips do not allow sockets connections, so (while Google rewrites their sdk to comply), I migrated my database to Realtime Database (since it was a better fit for us usage-wise), and have been using standard rest for sending and getting data, and for the "listener" functionality I have been using IKEventSource that listens to server-side events and updates them accordingly in my app clip. Seems to be a pretty good workaround so far.

Related

Rest API data stored in locally - Flutter

I have a requirement to store data locally to use within a Flutter mobile application. This stored data will be used for when the device is offline and will need to be updated, whilst offline.
On initial login of the application, data must be pulled from a REST API and stored locally to be displayed within the app.
Does anyone have any pointers as to what is the best method for this? I've looked at Sqflite but i can't seem to see any tutorials or documentation on setting this up using an API to 'fill' the data initially.
Any advice would be appreciated.
There are many ways to go about this.
One option is simply using dio, which has caching support built in.
Or, you could use something like hive or SharedPreferences along with http to to persist the data yourself (depending on what level of control you want/need).
You could also encapsulate the data in a state management solution like riverpod (specifically a FutureProvider in this case) which will soon have offline persistence support.
If building an application from scratch, I'd recommend the riverpod route (and it will soon have that offline persistence support).

How to build web interface for my Swift App/Firebase

I learned how to code in swift a little while back and created my first app. Now I'm trying to market it to customers, I realized that a web-interface might be what I need to scale this up to start attracting clients.
I use firebase as my backend now and would like to see what I can do to have a web interface that:
Allows customers to log in to see their unique data.
Updates info on my firebase backend
is Scaleable.
I'm not sure where to start nor how long this process will take. Any one has any ideas on where to get started?
I'm pretty sure Wordpress has a firebase plugin that could come in handy. Using Wordpress would save a lot of time actually designing a website, getting servers, and backend stuff like that. If you pay a little bit you can get rid of the .wordpress. com tag too, and your website can easily look professional.
Firebase is a realtime database and it is mostly used with mobile apps and some of the JavaScript applications like Angular and ReactJS. I think the best is to use ReactJS and there you can do a lot of the same functionalities you did on your app.
You can find a lot of tutorials online about how to do reactjs and firebase apps.
Have a look at this post and it should give you an idea about how it is done. It is gonna be a new thing if you are not familiar with javascript NodeJS / ReactJS development. (Firebase, react and redux wait for store to update)

Auto sync images and videos into webservice

How to auto sync the images and video from the app into the Api Web services.
Do we have any tutorials or source codes on this.
Thanks in advance!!!
There can be multiple approaches depending upon what you are trying to achieve and what backend you are using.
If you are using simple API web services, you need to write your own mechanism both on server as well as client side, which will identify records to be synced based on TimeStamp and few other columns in your DB
If you are open to use other Platforms like Parse.com, they provide in built APIs and libraries to take care of syncing logic
As you are trying to sync file(Images and Videos), you can also try DropBox, iCloud, or Google Drive. Here is a link to an article which i found in a quick search which uses CoreData and Dropbox
Let me know if this helps.

How to get data into Core-Data from an SQL Database?

I'm about to start an iOS project that requires pulling user's data from an SQL Database and viewing it within the App. Before I begin I'm looking for conformation that I'm taking the right (best) route.
My Plan:
App starts on login page (app will display data from another service)
App uses AFNetworking to post request to web service
Web service gets user data from SQL Database and sends back JSON
App uses JSONKit to parse the feed and load into Core-Data
App uses info from core-data to populate UI
Does this seem like an appropriate way to get the info into Core-Data from SQL? Any suggestions for doing things differently?
Thanks.
Are you receiving the response from the web server in JSON? If so, the fact that the server is using an SQL database is immaterial. What you need to know is how to parse JSON for inclusion in a core data store. Cocoa is my Girlfriend has a pretty good tutorial up.
Part 1
Part 2
To answer your comment, here's what I've done.
Display a login screen. The login credentials should be stored in the keychain for security. I've used SSKeychain for this.
To handle sending and receiving data from a web request your best option is to use a pre-built library. I've always used ASIHTTPRequest, but since it is no longer under active development, you should probably look around a bit before you commit to anything. I'm sure there are nicer and cleaner libraries out there.
You need to parse the JSON responses. I'm a fan of JSONKit. It's very fast, very easy to use, very robust.
Pulling data out of the core data store and displaying it in the interface will be no problem for you. If you create a new project in Xcode most of the setup will be done for you.
Now, there are a lot of projects out there that attempt to combine web requests, json parsing and core data loading into one framework. I've tried to use a few of these and haven't had much luck. The ones I've tried haven't been robust and very difficult to debug. Setting up your own request/parse/load code is not difficult at all, just a bit time consuming.
I am sure that there are a lot os ways to make implement this problem. Your solution is one of the popular solutions I guess but you could connect to the DB via a socket and talk with the database directly e.g. Going over a port 80 web site has the advantage that the possibility of some kind of firewall blocking the communication is very low. I would solve this kind of problem the same way I guess.

Should I start using core data?

I have started development of an app which is data reliant. It has a lot of information (using probably only 2 tables) so I am thinking core data is the way to go. However, I hate apps that only work when the user has an internet connection.
So what I would like to do is have saved core data on the device, and only download updates either periodically, on users' request or give them the option to update data when the app has loaded.
Is this the best solution and could someone please point me in the direction of a good blog or tutorial for this.
Many Thanks
The topics you ask about are really unrelated.
To implement your apps data model, Core Data is a fine solution. The iOS docs and sample code are good. if you need more I'm sure there are various blog posts but I don't have a recommendation. If you run into specific problems/issues there is tons of stuff on SO as well.
If you don't want to require a connection that's fine. This has nothing do with core data. It does have to do with apps functional requirements. At a minimum, store the apps current state in the data model and update at whatever interval you like, checking for a connection if that's required. Basically, whatever your app does, if a function requires a connection reflect that in the UI. Everything else should work fine without a connection.