Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing database between multiple swift apps

I need to be able to have 3 swift apps which can communicate with each other. Think of app 1 as a base app which communicates with a server and stores info in a local DB and app 2 and 3 need to read (and POSSIBLY write) to that DB created in app 1.

Looking on the net, this appears to be possible with 'app groups'.If all 3 apps are under the same app group, will they automatically have a 'shared folder' where I can create and/or store a Realm DB? Would app 2 and 3 use NSFileManager then to interact with this shared file? I can't seem to find any examples of this in action.

like image 952
user2363025 Avatar asked Nov 08 '22 05:11

user2363025


1 Answers

You need a central database to read and write to, from multiple client apps, that is an API at its simplest. In other words, you need an API for your Apps. It is possible that you might be thinking this is more challenging than a shared folder and shared Realm DB but that is not the case, you are actually making the problem more complex by trying to reinvent the wheel of how N number mobile apps share data with each other, it is of no matter that N number apps all reside on the same device, in iOS an app is in a Sandbox, and you trying to circumvent that.

My guess is that your approach to this problem is centered on using Realm DB, but Realm DB is probably not the right tool for the job as Realm DB is a LOCAL database serving ONE app, if Realm DB was designed to work with multiple apps it would be an API tool like Firebase or Amazon S3.

You need to create an API and the API just has one database backing it.

Say for example, App1 needs to save a picture that App2 needs to be able to retrieve and view.

Your API will have a method called:

SavePicture(byte[] picture)

Now App1 saves the picture by calling your API and the picture is saved, either in the database or on the server hard drive, either way there is a record in the database for the saved picture.

Now App2 wants new pictures, say there is a refresh button on App2, the refresh button touch calls your API, another method called

[byte[]] GetPictures()

The GetPictures API method returns an Array of byte[], each being an image, that App2 can display.

You might want to checkout Firebase, this seems to be a third party tool that people use that are not familiar with building APIs, or learn how to build an API, using PHP, Ruby on Rails, ASP.NET Web API, Python, etc. with a database that could be MySQL, PostgreSQL, Sql Server, MongoDB, RavenDB, etc.

like image 59
Brian Ogden Avatar answered Nov 14 '22 21:11

Brian Ogden