cordova-internal-plugins-group-storage v2.0.15
Sephora cordova plugins - Group Storage
Presentation
This plugin provides access to shared storage for applications sharing an AppGroupIdentifier. It uses CoreData, which is specific to iOS. In order to properly understand how the plugin works, remember that CoreData's shared storage is not like a local storage. It is a way to serialize classes. It uses an embedded SqlLite database for that purpose.
Features
- Save data by type
- Fetch the saved data
Installation
Add as a cordova dependency, in config.xml (with Cordova 6.x or higher)
<plugin name="cordova-internal-plugins-group-storage" spec="http://gitlab.estore.caas/cordova-plugins/group-storage#2.0.3" />
Compatibility
- iOS 9+
- Xcode >= 8.3
Using the plugin
Namespace and API
All the functions described in this plugin reside in the coredata.groupstorage
namespace.
All the functions have 2 callbacks as their last 2 parameters, the first being the success callback, and the second being the error callback.
The point is to store JSon Object in order to share them between different Cordova applications. The CoreData Entity is called JsonObj and has 3 properties :
data: String // the data to save
type: String // the type of the shared data
saved: Date // the last modification date
The main use case was to share the connected advisor's Id
or the last Customer's Id
.
Please note that every time an object of a certain type is saved, it erases the previously saved data
Use in TypeScript
All the calls should be made after platorm.ready()
has fired.
To save data for a customer, use the save
method:
var scd = (<any>window).coredata.groupstorage;
// 'customer' will be the identifier and 'superCustomerId' the data to save
this.scd.save('customer', 'superCustomerId', function (): void {
// do anything you'd like once the data is saved
}, function (err: any): void {
// handle the error {err}
});
To fetch data for a previously saved customer, use the fetch
method:
var scd = (<any>window).coredata.groupstorage;
this.scd.fetch('customer', function (obj: any): void {
console.log('TEST FETCH', obj);
}, function (err: any): void {
// handle the error {err}
});
when you fetch, the fetched object looks like :
{type: "customer", saved: "2017-05-12 05:52:57", data: "superCustomerId"}
Important notes
Model and entitlements file
In order to initialize properly, the core data stack requires the file describing the model to be added to the xcode project. A plugin hook generates this model in the proper format, and adds it automatically. The same way, the entitlements file, defining the app group name is generated by plugin hooks :
- for QA and Production, the app group is `group.fr.sephora.happyapp
- for Dev, the app group is 'group.fr.sephora.instoreapps'
The correct provisioning profile (without wildcards) must be used for the functionality to work.