4
votes

I am working on two different Xamarin forms apps and there is a need where I want to share the SQLite database of first app with second app.

I want to achieve Single Sign On approach for different xamarin forms apps, Where user will only log in in any of the app and can stay logged in in both the two apps.

I found below link which stats in android we can share the database:- Share LocalDB in two different android app

now I only need is similar thing in my xamarin forms app.

Any help will be grateful. Thanks :) Enjoy!

2
You can't do this in iOS. Sandboxing prevents apps from sharing a common datastoreJason

2 Answers

3
votes

In the case of iOS, it's sandboxed so sharing data between applications are so difficult. But there are still some ways to share data between applications.

In your case, I recommend you using App Groups. An App Group allows different applications (or an application and its extensions) to access a shared file storage location, please refer to Working with App Groups for more details.

After Adding an App to an App Group we can use the methods below to share data between applications:

NSUserDefaults:

var userDefaults = new NSUserDefaults("<your group ID>", NSUserDefaultsType.SuiteName);
userDefaults.SetString("user123", "userId");
userDefaults.Synchronize();

NSFileManager:

NSUrl appGroupDirectoryPath = NSFileManager.DefaultManager.GetContainerUrl("<your group Id>");
NSUrl dataBaseUrl = appGroupDirectoryPath.Append("dbName.db", false);
//You can try to copy your dataBase file to this url.
2
votes

Yes it is possible to share the data between two iPhone apps ... If anybody need more information on this please go through the below link which will explain how to achieve...

Using your App Group

App Groups are the scheme iOS uses to allow different apps to share data. If the apps have the right entitlements and proper provisioning, they can access a shared directory outside of their normal iOS sandbox. Sandboxing still applies except for a single exception.

This is probably almost automatic, but when you get into iOS app provisioning you can't assume anything. What's supposed to happen is that you just turn on the "app groups" entitlement in Xcode for the app and for any extensions..


Link for:- Sharing the app extension

@Land Lu - MSFT Thanks for the suggestion your answer led me to get it done.