License | MIT |
ReleasedLast Release | Nov 2024 |
Maintained by Luis Sanches, Rob Weber, James Go, Britton Katnich, Yasmeen Taj, Syed Yusuf, Syed Yusuf.
MASStorage is the data peristence framework of the iOS Mobile SDK, which is part of CA Mobile API Gateway. It stores, manages, and accesses data in a private local and cloud.
The MASStorage framework comes with the following features:
Contributions are welcome and much appreciated. To learn more, see the Contribution Guidelines.
MASStorage supports multiple methods for installing the library in a project.
To integrate MASStorage into your Xcode project using CocoaPods, specify it in your Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
pod 'MASStorage'
Then, run the following command using the command prompt from the folder of your project:
$ pod install
For manual install, you add the Mobile SDK to your Xcode project. Note that you must add the MASFoundation library. For complete MAS functionality, install all of the MAS libraries as shown.
Copy items if needed
.File->Add files to 'project name'
and add the msso_config.json file from your project folder.-ObjC
for Other Linker Flags
.#import <MASFoundation/MASFoundation.h>
#import <MASStorage/MASStorage.h>
Store/Retrieve local data is done using different permission types. You control permissions using the following enumeration values for the MASLocalStorageSegment:
MASLocalStorageSegmentApplication
This segment is used to store data pertinent only to the Application. For example, you can store the application configuration. Data stored here is shared across users within the app.
MASLocalStorageSegmentApplicationForUser
This segment is used to store data pertinent to a specific user within the app. For example, in a game app, you can store the user game score or user game state.
To start using local storage in your app, the SDK needs to enable it. The following process creates the LocalStorage DB with a predefined schema.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//
// Enable Local Storage in the App
//
[MAS enableLocalStorage];
//
// Start the SDK
//
[MAS start:nil];
return YES;
}
Any object conforming to NSData
or NSString
can be saved into the local storage.
- (void)saveObjectMethod
{
NSString *myObject = @"someString";
NSString *key = @"someKey";
NSString *type = @"objectType";
//
// Save object to Local Storage
//
[MASLocalStorage saveObject:myObject withKey:key type:type mode:MASLocalStorageSegmentApplication completion:^(BOOL success, NSError *error) {
//Your code here
}];
}
Using encryption, saves any object conforming to NSData
or NSString
. It uses a password, that is set by parameter in the method, to encrypt the object before saving it in the local storage.
- (void)saveEncryptedObjectMethod
{
NSString *myObject = @"someString";
NSString *key = @"someKey";
NSString *type = @"objectType";
//
// Save object to Local Storage
//
[MASLocalStorage saveObject:myObject withKey:key type:type mode:MASLocalStorageSegmentApplication password:@"S0m3Pwd!" completion:^(BOOL success, NSError *error) {
//Your code here
}];
}
- (void)findObjectMethod
{
//
// Find Local Storage Data
//
[MASLocalStorage findObjectUsingKey:key mode:MASLocalStorageSegmentApplication completion:(void (^)(MASObject *object, NSError *error))completion; {
//Your code here
}];
}
- (void)deleteObjectMethod
{
//
// Delete object from local storage
//
[MASLocalStorage deleteObjectUsingKey:key mode:MASLocalStorageSegmentApplication completion:^(BOOL success, NSError *error) {
//Your code here
}];
}
- (void)findObjectsMethod
{
//
// Find all Local Storage Data by Mode
//
[MASLocalStorage findObjectsUsingMode:MASLocalStorageSegmentApplication completion:^(NSArray *objects, NSError *error) {
//Your code here
}];
}
- (void)viewDidLoad
{
[super viewDidLoad];
//Add Observer for Notifications from the Mobile SDK
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didSaveToLocalStorageNotification:)
name:MASStorageOperationDidSaveToLocalStorageNotification
object:nil];
}
Store/Retrieve cloud data is done using different permission types. You control permissions using the following enumeration values for the MASLocalStorageSegment:
MASCloudStorageSegmentUser
This segment is used to store data pertinent only to a specific user. For example, if you want to extend the SCIM user profile. Data stored using this segment can be accessed by the same user via different apps.
MASCloudStorageSegmentApplication
This segment is used to store data pertinent only to the Application. For example, you can store the application configuration. Data stored here is shared across users within the app.
MASCloudStorageSegmentApplicationForUser
This segment is used to store data pertinent to a specific user within the app. For example, in a game app, you can store the user game score or user game state.
Any object conforming to NSDate
or NSString
can be saved into the cloud storage.
- (void)saveObjectMethod
{
NSString *myObject = @"someString";
NSString *key = @"someKey";
NSString *type = @"objectType";
//
// Save object to Cloud Storage
//
[MASCloudStorage saveObject:myObject withKey:key type:type mode:MASCloudStorageSegmentApplication completion:^(BOOL success, NSError *error) {
//Your code here
}];
}
- (void)findObjectMethod
{
//
// Find Cloud Storage Data
//
[MASCloudStorage findObjectUsingKey:key mode:MASCloudStorageSegmentApplication completion:(void (^)(MASObject *object, NSError *error))completion; {
//Your code here
}];
}
- (void)deleteObjectMethod
{
//
// Delete object from Cloud Storage
//
[MASCloudStorage deleteObjectUsingKey:key mode:MASCloudStorageSegmentApplication completion:^(BOOL success, NSError *error) {
//Your code here
}];
}
- (void)findObjectsMethod
{
//
// Find all Cloud Storage Data by Mode
//
[MASCloudStorage findObjectsUsingMode:MASCloudStorageSegmentApplication completion:^(NSArray *objects, NSError *error) {
//Your code here
}];
}
Copyright (c) 2016 CA. All rights reserved.
This software may be modified and distributed under the terms
of the MIT license. See the LICENSE file for details.