5

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.

user2363025
  • 6,365
  • 19
  • 48
  • 89
  • You can't force a user to install 3 apps to be able to use one of them. You need to implement a server side which can hold all of your data and push changes to the other apps. You can have multiple apps that can work together, but they cannot share internal database. – JoakimE Nov 29 '16 at 17:25

1 Answers1

1

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.

Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
  • App1 has an API which connects with the server as I mentioned in the question. All other apps communicate with the local db created in app 1 after retrieving info from the server and storing locally. All server requests need to go through app1 – user2363025 Nov 29 '16 at 18:38
  • @user2363025 You need an API, everything goes through the API, great that you already have one, use it for App2 and App3 – Brian Ogden Nov 29 '16 at 18:51
  • @user2363025 aren't you trying to use Realm DB to solve the sharing of data between App1 and App2? – Brian Ogden Nov 29 '16 at 18:51
  • @user2363025 aren't you trying to use Realm DB to solve the sharing of data between App1 and App2? – Brian Ogden Nov 30 '16 at 21:24
  • It's a complex system so I won't get into the reasons behind the necessity, but yes what I needed to do was have app1 connect to a server and retrieve info and store locally, then multiple apps could then access this info locally on a shared DB. I got it working with app groups. – user2363025 Nov 30 '16 at 23:46